关于jquery的each方法 $(":input").each(function(){ if($(this).attr("type")=='button'){ alert("button"); } });获取页面元素,并判断元素类型,为什么象上面那样写不行呢?,应该怎么改? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转一下试试if($(this).attr("type").toLowerCase()=='button') 你把所有的代码都贴出来吧! 或者用firebug看看? $("input[type='button']")楼主是要这个功能么,获取所有 type为button类型的 input 可以的,你alert属性看看$(":input").each(function(){ alert($(this).attr("type"));//看看有没有其他字符 if($(this).attr("type")=='button'){ alert("button"); } }) $("input[type=button]").each(function(){ alert("button"); }); <html><head><script src ="jquery-1.4.2.js" ></script></head><body><input type = "button"><script>$('input').each(function() { if(($(this).attr('type'))=='button'){ //注意书写规范 js内部最好都用''单引号 alert('button'); } });</script></body></html>应该是你的if语句写错了啊!!! [求大神幫助] 'undefined' 是 null 或不是一個物件..."唯獨ie8出現" 如何申请Google Maps API 密钥? vs 下我用后台保存了一个xml文件,但用前台js用绝对路径调用时,提示没有权限 在JavaScript中,函数没有引用参数? 一个简单的问题,新手求助 IE中JS cloneNode的问题,是不是一个bug呢? prototype问题. 我在网站首页放了一幅对联广告,他怎么就是不跟着鼠标动啊,不知道是什么原因 js实现无前台无限级分类 像怎么怎么对图片进行操作!?(急) javascript控制图片不循环显示 请大大们帮帮忙,day day up
if($(this).attr("type").toLowerCase()=='button')
楼主是要这个功能么,获取所有 type为button类型的 input
可以的,你alert属性看看
$(":input").each(function(){
alert($(this).attr("type"));//看看有没有其他字符
if($(this).attr("type")=='button'){
alert("button");
}
})
$("input[type=button]").each(function(){
alert("button");
});
<head>
<script src ="jquery-1.4.2.js" ></script>
</head>
<body>
<input type = "button">
<script>
$('input').each(function() {
if(($(this).attr('type'))=='button'){ //注意书写规范 js内部最好都用''单引号
alert('button');
}
});
</script>
</body>
</html>
应该是你的if语句写错了啊!!!