$("input:text", document.forms[0]).each(function(){alert(this.name)});
实例代码二
function test(){
var obj=$("input:checked[name='chcekname']");
$.each(obj, function(i,item){
if($(item).parent().parent().find("td:eq(3)").html()==""){
$(item).parent().parent().find("td:eq(3)").html("testvalue");
}
});
}
这里是通过checkbox的name遍历所有checkbox的,不是id或者type.
$("input:checked[name='chcekname']")用来获取所有的被选中checkbox,
$(item).parent().parent().find("td:eq(3)").html()==""用来判断与此相邻的第四个单元格中是否有值,若无值,则用testvalue填充
看个完整的实例
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/网页特效" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script><script type="text/javascript">//<![cdata[$().ready(function () { $("#cardnum").focus().select(); $("input[type='text']").each(function (i) { $(this).keypress(function (e) { if (e.which == 13) { $("input[type='text']").eq(i + 1).focus(); return false; } }); });})//]]></script></head><body><form id="form1" name="form1" method="post" action="do.jsp教程?action=adduser"><table cellpadding="0" cellspacing="0" border="0" width="60%"> <thead> <tr> <td colspan="2"><h1>添加读者</h1></td> </tr> </thead> <tbody> <tr> <th>会员卡号:</th> <td> <input type="text" name="cardnum" id="cardnum" /></td> </tr> <tr> <th>真实姓名:</th> <td> <input type="text" name="truename" /></td> </tr> <tr> <th>密 码:</th> <td> <input type="password" name="password" /></td> </tr> <tr> <th>重复密码:</th> <td> <input type="password" name="repassword" /></td> </tr> <tr> <th>联系电话:</th> <td> <input type="text" name="phone" /></td> </tr> <tr> <th>状 态:</th> <td> <select name="status" id="status"> <option value="1">正常</option> <option value="0">失效</option> </select></td> </tr> <tr> <td colspan="2"><div class="buttons"><input type="submit" name="button" id="button" value="提交保存" class="submit" /> <input type="reset" name="button2" id="button2" value="重置" /></div></td> </tr> </tbody></table></form></body></html>