读书人

js checkbox 有关问题! 。

发布时间: 2013-01-08 14:02:14 作者: rapoo

js checkbox 问题!!!急 。。。。
jsp 页面:

<table width="500" height="450">
<tr><th colspan="4" height="24">业务员列表</th></tr>
<tr>
<s:iterator value="empList" var="user" status="st">
<td><input type="checkbox" id="chks" value="<s:property value="#user.empId"/>"/>
<span onclick="e(this);" value="<s:property value="#user.empName"/>"><s:property value="#user.empName"/></span>
</td>
<s:if test="#st.modulus(4) == 0">
<s:if test="#st.last">
</tr>
</s:if><s:else>
<tr></tr>
</s:else>
</s:if>
</s:iterator>
</table>

js 代码:

function setIcpCode() {

var chkValue ="";
var chk=document.getElementsByTagName("input");
for(var i=0;i<chk.length;i++){
if(chk[i].checked){
chkValue =chk[i].value;
}
}
window.opener.document.getElementById("callID").value=chkValue;
window.close();
}
function e(s){
var chkValue =s.value;
window.opener.document.getElementById("caller").value=chkValue;
setIcpCode();
}

我想让选中《span》时候checkbox 自动选中。。求解
[解决办法]
选中文字即为选中checkbox, 不需要一行代码的, 要的只是把span换成label就好。

此外, 来论坛, 最好把页面生成的html发出来, 这样我们更轻松点。

<html>
<head>
<title>测试form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<style type="text/css">
label{ cursor:pointer; }
</style>
<script type="text/javascript">
</script>
</head>
<body>
<div id="div1">
<table width="500" border="1" cellspacing="1" >
<tr>
<th colspan="4" height="24">
业务员列表
</th>
</tr>
<tr>
<td>
<input type="checkbox" id="chks" value="1" />
<label for='chks' >1</label>
</td>
<td>


<input type="checkbox" id="Checkbox1" value="2" />
<label for='Checkbox1' >2</label>
</td>
<td>
<input type="checkbox" id="Checkbox2" value="3" />
<label for='Checkbox2' >3</label>
</td>
<td>
<input type="checkbox" id="Checkbox3" value="4" />
<label for='Checkbox3' >4</label>
</td>
</tr>
<tr>
</tr>
</table>
</div>
</body>
</html>

读书人网 >JavaScript

热点推荐