如何在angularjs中拥有一个图像占位符

时间:2015-06-04 06:20:30

标签: css angularjs

我有一个搜索输入框,当前未选中时会显示Search here但是我可以使用图片而不是文字吗?

enter image description here

<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 link

1 个答案:

答案 0 :(得分:0)

你可以直接用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="Search"