zhangsuyun2012的gravatar头像
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>

js操作复选框字符串


最代码官方编辑于2014-9-2 9:55:19


打赏

文件名:test.java,文件大小:1K 下载
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友