0

可能重复:
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。

感谢您更正代码。

4

2 回答 2

1

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

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

于 2012-11-21T14:59:08.793 回答
0

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

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

除此之外,正如评论中提到的,IE9 不支持placeholder(参见caniuse.com)!

于 2012-11-21T15:05:42.727 回答