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

how to make $(":text[placeholder]" to work in IE

本文关键字:quot 工作 placeholder IE 何使 text      更新时间:2023-09-26

我的代码包含以下几行:

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

它在chrome和ff上工作良好,但在IE8中出现以下错误。

 Object doesn't support this property or method

我该如何解决这个问题?

你也可以这样做:

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

从这里借用的属性检查代码