关于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语句写错了啊!!! javascript怎么读取一个二进制的数据 熟悉jquery ui的进 <body onload = "initinfo(${param.info});">无法弹出对话框显示info DIV 层的拖动问题 163编辑器在服务器上不可用 仿jq写一个小js框架,现在出现问题,请各位帮忙解决一下,谢 json对象转换成json字符串 在vc下能调用google map或者51ditu的api吗? easy-ui里面的data-options自定义属性 高分求关联菜单,请各位大大帮忙呀 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语句写错了啊!!!