日期:2014-05-17 浏览次数:20446 次
<tr> <td><span text="建材" value1="7" onclick ="checkProd(); "><input id="ctl00_ContentPlaceHolder1_cblParent_0" type="checkbox" name="ctl00$ContentPlaceHolder1$cblParent$0" /><label for="ctl00_ContentPlaceHolder1_cblParent_0">建材</label></span></td><td><span text="型钢" value1="14" onclick ="checkProd(); "><input id="ctl00_ContentPlaceHolder1_cblParent_1" type="checkbox" name="ctl00$ContentPlaceHolder1$cblParent$1" /><label for="ctl00_ContentPlaceHolder1_cblParent_1">型钢</label></span></td></tr>
<script type="text/javascript"> function checkProd() { // 再IE9和Chome下不能运行 var lblProdSelected = document.getElementById("<%=lblProdSelected.ClientID %>"); var hidProdSelected = document.getElementById("<%=hidProdSelected.ClientID %>"); var ckelems = document.getElementById("<%=cblParent.ClientID %>").getElementsByTagName("input"); var spelems = document.getElementById("<%=cblParent.ClientID %>").getElementsByTagName("span"); for (var i = 0; i < ckelems.length; i++) { if (ckelems[i].type == "checkbox") { var nm = spelems[i].text; var id = spelems[i].value1; var text = lblProdSelected.innerText; var t = nm + "|" + id + ","; if (ckelems[i].checked) { if (text == "") { lblProdSelected.innerText += t; hidProdSelected.value += t; } else { if (text.indexOf(t) == -1) { //不包含则加入 lblProdSelected.innerText += t; hidProdSelected.value += t; } } } else { lblProdSelected.innerText = lblProdSelected.innerText.replace(t, ""); hidProdSelected.value = hidProdSelected.value.replace(t, ""); } } } } </script>