2014-10-08 106 views
0

我希望能够在可能的情况下打开/关闭搜索框中的占位符。在html文本/搜索元素中关闭(忽略)占位符属性

<input type="text" placeholder="Enter name" /> 
<input type="search" placeholder="Type to search" /> 

我迄今为止尝试:

input[type="search"]::-webkit-input-placeholder{ 
    content: ""; 
    color:red; /*test selector*/ 
} 

的jsfiddle http://jsfiddle.net/cqocxhzt/1/具有角这样的

+0

@epascarello你能给我一个 - *多一点* - 直接的答案吗?我没有得到它 – celerno 2014-10-08 17:22:05

+2

尝试'颜色:透明',如果你想用CSS来“隐藏”占位符。 – lexith 2014-10-08 17:23:09

回答

1

一种方法是:

在控制器:

$scope.placeholder_value1 = ""; //empty 
$scope.placeholder_value2 = "some value"; //some value 

In the view:

<input type="text" placeholder="{{placeholder_value1}}" /> 
<input type="text" placeholder="{{placeholder_value2}}" /> 
+0

这是 - *实际上* - 我将在下一个设计中考虑的答案,但不是现在手动移除占位符的懒惰解决方案(可能会在短时间内再次添加它们)。谢谢! – celerno 2014-10-08 17:35:05