0 0

如何全选 s:iterator 中嵌套的 所有 s:checkbox 5



<s:iterator value="cancellationDtos" status="cancellationDto">
<tr>
<td><s:checkbox theme="simple" name="selectedids" fieldValue="%{cancellationjstbid}"/>
</td>
</tr>
<s:iterator>

我在 s:iterator 中用了 s:checkbox , 请问如何写javascript 才能全选 checkbox ?
我是否一定要用 把 s:iterator 放在form中 ,放在table中也可以吗?

谢谢

问题补充:
Anddy 写道
下面是全选以及反选,var arryObj = document.getElementsByName("selectedids")
==========================================
function selectAll() {
	var arryObj = document.getElementsByName("selectedids")
	for ( var i = 0; i < arryObj.length; i++) {

		if (typeof arryObj[i].type != "undefined"
				&& arryObj[i].type == 'checkbox')
			arryObj[i].checked = true;
	}
}

function unSelectAll() {
	var arryObj = document.getElementsByName("selectedids");
	for ( var i = 0; i < arryObj.length; i++) {
		if (typeof arryObj[i].type != "undefined"
				&& arryObj[i].type == 'checkbox')
			;
		arryObj[i].checked = false;
	}
}



请问在普通的 html 元素里能用 OGNL吗?似乎只能在 struts2自带的Taglib 里用, 我要用下面的写法,value就拿不到正确的值了
<input type="checkbox" name="selectedids" value="%{cancellationjstbid}">
2010年3月24日 04:20

4个答案 按时间排序 按投票排序

0 0

采纳的答案

下面是全选以及反选,var arryObj = document.getElementsByName("selectedids")
==========================================

function selectAll() {
	var arryObj = document.getElementsByName("selectedids")
	for ( var i = 0; i < arryObj.length; i++) {

		if (typeof arryObj[i].type != "undefined"
				&& arryObj[i].type == 'checkbox')
			arryObj[i].checked = true;
	}
}

function unSelectAll() {
	var arryObj = document.getElementsByName("selectedids");
	for ( var i = 0; i < arryObj.length; i++) {
		if (typeof arryObj[i].type != "undefined"
				&& arryObj[i].type == 'checkbox')
			;
		arryObj[i].checked = false;
	}
}

2010年3月24日 08:20
0 0

使用jquery的话, 一条语句就能搞定
首先要设置form或table的id为datas

看例子

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript"  src="jquery-1.2.6.min.js"></script>
<script language="javascript"> 
	function checkAll()
	{
		$("#datas :checkbox").each(function (){
			$(this).attr("checked","checked");
		
		})
	
	}

</script> 
<style>

</style>

</head>
<body>
<input type="button" value="check all" onclick="checkAll()" />
<form id="datas" >
<input type="checkbox" value="check it" /> 
<input type="checkbox" value="check it" /> 
<input type="checkbox" value="check it" /> 
<input type="checkbox" value="check it" /> 
<input type="checkbox" value="check it" /> 
<input type="checkbox" value="check it" />
</form>
 
</body> 

</html>


2010年3月24日 08:27
0 0

补充:

引用
我是否一定要用 把 s:iterator 放在form中 ,放在table中也可以吗?

放在jsp里面就行,后台能解析的。解析后成html代码返回前台浏览器显示。

2010年3月24日 08:23
0 0

放在table里当然可以,但是如果你还要提交表单把选中的数据提交到后台,
那就要放在form里

2010年3月24日 08:20

相关推荐

Global site tag (gtag.js) - Google Analytics