Jquery 占位符在IE 9中不起作用,但在chrome中可以使用
可能重复:Jquery 占位符在IE 9中不起作用,但在chrome中可以使用,jquery,html,internet-explorer,Jquery,Html,Internet Explorer,可能重复: 一个非常简单的测试 我的代码: <div id="generatePinsDialog" > <label for="newCount" style="width: 400px;"> How many?</label> <input id="newCount" type="text" size="25" placeholder="Enter the number!" /> <br /> 它在谷歌chrome上运行
一个非常简单的测试 我的代码:
<div id="generatePinsDialog" >
<label for="newCount" style="width: 400px;">
How many?</label>
<input id="newCount" type="text" size="25" placeholder="Enter the number!" />
<br />
它在谷歌chrome上运行,但在IE 9上运行
感谢您更正代码。占位符属性在IE中不起作用,只在现代浏览器中起作用。不过,IE10现在终于做到了
大多数情况下,像这样的东西在现代浏览器中都会起作用,但你需要经常仔细检查它在IE中是否起作用,而IE通常比其他浏览器落后数年。一个位置是假设您只想检查浏览器是否支持占位符,您可以使用以下代码:
jQuery(function() {
jQuery.support.placeholder = ( 'placeholder' in (document.createElement( 'input' )) );
});
除此之外,如评论中所述,IE9不支持占位符
(请参阅) 但是如果你在JSFIDLE中查看它,它不会在IE9中显示文本。如果你绝对需要这种功能,那么使用Javascript是目前唯一一个跨浏览器兼容的解决方案。
jQuery(function() {
jQuery.support.placeholder = ( 'placeholder' in (document.createElement( 'input' )) );
});