是占位符不被IE 9支撑。但是你可以环顾四周,如JavaScript一些替代实现这个很容易
<input type="text" placeholder="test" value="placeholder text"
onfocus="if (this.value=='placeholder text') this.value = ''" onblur="if (this.value=='') this.value = 'placeholder text'"/>
但是你需要照顾,而使用这种方法,因为这种方法设置textbox
的value
。所以当你找回它时,你会得到它的价值。所以,无论何时使用它,您都需要检查占位符值。
你的功能会是这样
function ClickYes() {
// for modern browsers
$('#txtMsg').attr('placeholder', 'Tell me more');
// for older browsers
$('#txtMsg').val('Tell me more');
$('#txtMsg').css('color','#CCC');
}
现在你需要处理focus
和blur
事件,使其完成这样
$(document).ready(function() {
$("#txtMsg").focus(function() {
if ($(this).val() == 'Tell me more') {
$(this).val('');
$(this).css('color', 'black');
}
});
$("#txtMsg").blur(function() {
if (!$(this).val()) {
$(this).val('Tell me more');
$('#txtMsg').css('color', '#CCC');
}
});
});
Js Fiddle Demo
Js Fiddle Demo 2
IE9不支持使用'placeholder'属性,但有解决方法。看看这个答案的类似问题:http:// stackoverflow。com/a/13281620/1423456 –