论坛首页 入门技术论坛

利用javascript操作html:multibox、html:checkbox两种复选框

浏览 2433 次
该帖已经被评为新手帖
作者 正文
   发表时间:2009-03-03  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page contentType="text/html;charset=GBK"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
     <script type="text/javascript">
        function chooseAll() {
            var str ;
            var name ;
            //得到属性 property=choosePerson 这样的 struts 标签
            var allSelect = document.shareAddressBookForm.elements["choosePerson"];
			for (i = 0; i < document.shareAddressBookForm.elements.length; i++) {
	  			str = document.shareAddressBookForm.elements[i].type;
	  			name = document.shareAddressBookForm.elements[i].name;
	  			
	  			if(name.indexOf("realName") != -1) {
	  				if (allSelect.checked == true) {
						document.shareAddressBookForm.elements[i].checked = true;
	  				}else {
	  					document.shareAddressBookForm.elements[i].checked = false;
	  				}
	  			}
			} 
	    }
     </script>
</head>
<body>

 <html:form action="/addressBook/shareAddressBookAction2.do">
 	<table align="center" width="775" border="0" cellpadding="0" cellspacing="0">
 	
 	<tr>
 		<td bgcolor='yellow'><html:checkbox property="choosePerson" onclick="chooseAll();" />全选/反选</td>
 	</tr>
 	
 	<tr style='BACKGROUND:#ffffff'>
 		<logic:notEmpty name="allUserList"> <!-- 判断是否为空 不为空就进行下面操作 -->
		    <logic:iterate id="bean" name="allUserList" scope="session"><!-- 从session中取出ArrayList 并遍历它 -->
				
					<td align='left' width="775">
						<!-- input type='checkbox' name='checkbox1' value='<bean:write name="bean" property="ID" />' /-->
						<!-- html:checkbox property="name" value="${bean.ID}"/ -->
						<html:multibox property="realName" value="${bean.ID}" />
						<bean:write name="bean" property="name"/>
			  </td>
			</logic:iterate>
		</logic:notEmpty>
	  </tr>
		<tr>
			<td colspan='2'>
				<html:submit value='共享' />
				<html:reset  value='重置' />
				<html:button property='button1' value='返回' onclick="javascript:history.go(-1);"></html:button>
			</td>
		</tr>
   </table>
 </html:form>
 
</body>
</html>

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics