zhangsuyun2012
2012-10-24 20:29:29
js操作复选框字符串
<html> <head> <script type="text/javascript"> var str = "111,aaa;222,bbb;"; function check(id, name, checkid) { var check = document.getElementById(checkid); if (check.checked) { str = str + id + "," + name + ";"; } else { var temp = ""; if (str != "" && str != null) { var array1 = str.split(";"); if (array1 != null && array1 != "") { for ( var i = 0; i < array1.length; i++) { var array2 = array1[i].split(","); if (array2 != null && array2 != "") { if (array2[0] != null && array2[0] != "" && array2[0] != id) { temp = temp + array2[0] + "," + array2[1] + ";"; } } } } } str = temp; } document.getElementById("display").value = str; } </script> </head> <body> <input type="checkbox" id="check1" onclick="check('333','ccc','check1')">选择1 <input type="checkbox" id="check2" onclick="check('444','ddd','check2')">选择2 <input type="checkbox" id="check3" onclick="check('555','eee','check3')">选择3 <input type="text" id="display" size="100"> </body> </html>
由最代码官方编辑于2014-9-2 9:55:19
猜你喜欢
请下载代码后再发表评论
相关代码
最近下载
abcdljw LV20
2021年12月28日