如何在AngularJS中设置图像占位符

3

我有一个搜索输入框,当它没有被选中时,它会显示“Search here”,但我可以用一张图片代替文字吗?

enter image description here

code

<input id="autoComplete" type="text" ng-model="selected" typeahead="task.name for task in taskList | filter:$viewValue | limitTo:20" class="form-control" typeahead-on-select='onSelect($item, $model, $label)' placeholder="Search here" typeahead-focus-first="true" ng-disabled="loading" ng-blur="autocompleteBlurred()" />

这里有一个plunker链接,您可以查看。


请查看此线程 https://dev59.com/fWYr5IYBdhLWcg3wVYwg - kachhalimbu
你也可以查看这个链接:https://dev59.com/137aa4cB1Zd3GeqPkwbQ#22655903。 - dfsq
1个回答

1
你可以直接使用CSS来完成。
input#autoComplete {
    background-image: url(https://cdn1.iconfinder.com/data/icons/hawcons/32/698627-icon-111-search-16.png);
    background-position: 10px center;
    background-repeat: no-repeat;
    border: 1px solid #ccc;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    -ms-border-radius: 4px;
    -o-border-radius: 4px;
    border-radius: 4px;
    padding: 10px 5px;
    text-indent: 20px;
    -webkit-transition: all 0.2s;
    -moz-transition: all 2s;
    transition: all 0.2s;
}
input#autoComplete:focus {
    background-position: -20px center;
    text-indent: 0;
}

请查看此 plunker

如果您想要文本,请不要从输入框中删除 placeholder="搜索"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接