【问题标题】:Placeholder is not working in IE 9 but is okay in chrome [duplicate]占位符在 IE 9 中不起作用,但在 chrome 中没问题 [重复]
【发布时间】:2012-11-09 20:34:59
【问题描述】:

可能重复:
placeholder in ie9

http://jsfiddle.net/zhshqzyc/mGAPs/中的一个非常简单的测试

我的代码:

<div id="generatePinsDialog" >
<label for="newCount" style="width: 400px;">
    How many?</label>
<input id="newCount" type="text" size="25" placeholder="Enter the number!" />
<br />

并且:

jQuery(function() {
     jQuery.support.placeholder = false;
     test = document.ElementById("newCount");
     if('placeholder' in test) jQuery.support.placeholder = true;
});

它适用于谷歌浏览器,但适用于 IE 9。

感谢您更正代码。

【问题讨论】:

标签: jquery html internet-explorer


【解决方案1】:

placeholder 属性在 IE 中不起作用,仅在现代浏览器中起作用。不过,IE10 现在终于可以了。

大多数情况下,这样的事情可以在现代浏览器中运行,但您需要始终仔细检查它是否可以在 IE 中运行,这通常比其他浏览器晚几年。一个地方是http://caniuse.com/

【讨论】:

    【解决方案2】:

    假设您只是想检查浏览器是否支持placeholder,您可以使用此代码:

    jQuery(function() {
         jQuery.support.placeholder = ( 'placeholder' in (document.createElement( 'input' )) );
    });
    

    除此之外,如 cmets 中所述,IE9 不支持placeholder(见caniuse.com)!

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 2018-01-17
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 2012-07-03
      • 2015-03-31
      • 2013-11-25
      相关资源
      最近更新 更多