日期:2014-05-16 浏览次数:20401 次
<html > <head > <meta http-equiv="Content-Type" content="text/html; charset=gb2312" > <title >JK:支持民族工业,尽量少买X货 </title > </head > <script language="javascript" type="text/javascript" > function setText() { var chk =document.getElementsByName("C1"); var arr = []; for(var i=0;i<chk.length;i++) { if(chk[i].checked) { arr.push(chk[i].title); } } document.getElementById("T1").value = arr.toString(); } </script > <body > <div> <input type="checkbox" name="C1" value= '2010001 ' title="王海" >王海 <input type="checkbox" name="C1" value= '2010002 ' title="李XX">李XX <input type="checkbox" name="C1" value= '2010003 ' title="陈师">陈师 <input type="checkbox" name="C1" value= '2010004 ' title="甲某">甲某 </div> <input type="text" name="T1" style="width:300px" > <input type="button" value=" b1 " onclick="setText()" > </body > </html >
------解决方案--------------------
楼上的对,可以自己定义一些属性在标签里,然后通过getAttribute("名称")来获得自定义属性。例如:
<script>
function show(){
var a=document.getElementsByName("C1"),b=document.getElementById("T1")
for(i=0;i<a.length;i++){if(a[i].checked){b.value+=a[i].getAttribute("tag")}}
}
</script>
<input type="checkbox" name="C1" value='2010001' tag='王海'>王海
<input type="checkbox" name="C1" value='2010002' tag='李XX'>李XX
<input type="checkbox" name="C1" value='2010003' tag='陈师'>陈师
<input type="checkbox" name="C1" value='2010004' tag='甲某'>甲某
<input type="text" name="T1" >
<input type="button" name="b1" onclick="show()">