得到HTML标签的ID和NAME <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- function GetNameNId(obj) { alert("当前控件的name为:"+obj.name) alert("当前控件的id为:"+obj.id) } //--> </SCRIPT> <BODY> <INPUT TYPE="text" NAME="testname" id="testid" οnclick="GetNameNId(this)"> <div name='divtest' id='divtest' οnclick="GetNameNId(this)">click me</div> </BODY> </HTML> JS实现复选框全部选中或取消选中效果 <!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> <title> 复选框全选/不选效果 </title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <meta http-equiv="Content-Language" content="zh-CN" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <mce:script type="text/javascript"><!-- function selectall(obj) { var temp = document.getElementsByName("cb"); for (var i =0; i<temp.length; i++) { temp[i].checked = obj.checked; } } function cancel(obj,all) { var flag = 0; var all = document.getElementsByName(all)[0]; if (!obj.checked) { all.checked = false; } else { for (var i=0; i<document.getElementsByName(obj.name).length; i++) { if (!document.getElementsByName(obj.name)[i].checked) { all.checked = false; } else { flag++; } } if (flag == document.getElementsByName(obj.name).length) { all.checked = true; } } } // --></mce:script> </head> <body> <input type="checkbox" name="cb" value="1" οnclick="cancel(this,'cball')" />1<br /> <input type="checkbox" name="cb" value="2" οnclick="cancel(this,'cball')" />2<br /> <input type="checkbox" name="cb" value="3" οnclick="cancel(this,'cball')" />3<br /> <input type="checkbox" name="cb" value="4" οnclick="cancel(this,'cball')" />4<br /> <input type="checkbox" name="cb" value="5" οnclick="cancel(this,'cball')" />5<br /> <input type="checkbox" name="cb" value="6" οnclick="cancel(this,'cball')" />6<br /> <input type="checkbox" name="cb" value="7" οnclick="cancel(this,'cball')" />7<br /> <input type="checkbox" name="cb" value="8" οnclick="cancel(this,'cball')" />8<br /> <input type="checkbox" name="cball" οnclick="selectall(this)" />选择所有<br /> </body> </html>