如何使$(“:text [placeholder]”在IE中工作

时间:2012-12-21 12:22:35

标签: javascript jquery css internet-explorer internet-explorer-8

我的代码包含以下几行:

 $(":text[placeholder], :password[placeholder]").each(function(){
    //some code
  });

它在chrome和ff上工作正常,但在IE8中得到以下错误。

 Object doesn't support this property or method

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

或者你可以试试这个:

$("input[type='text'], input[type='password']").filter(function(){
    var attr = $(this).attr('placeholder');
    return typeof attr !== 'undefined' && attr !== false;
}).each(function(){
    //some code
});

here

借来的属性检查代码
相关问题