首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

checkbox 的 onclick 不能调用javascript里面定义的函数,该如何处理

2012-01-28 
checkbox 的 onclick 不能调用javascript里面定义的函数先说一下,我是想但选择checkbox的时候,调用javascr

checkbox 的 onclick 不能调用javascript里面定义的函数
先说一下,我是想但选择checkbox的时候,调用javascript里面定义的函数
但是却不能进入函数
而我在onclick上面添加alert的时候却是可以响应的
这是为什么,麻烦各位高手们指点下!谢谢
代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@include file="/common/common.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="javascript" src="script/public.js"></script>
<link href="style/oa.css" rel="stylesheet" type="text/css">
<title>授权管理</title>
</head>
<script type="text/javascript" language="javascript">
  var XMLHttpReq;

  //创建XMLHttpRequest对象  
  function createXMLHttpRequest() {
  if(window.XMLHttpRequest) { //Mozilla 浏览器
  XMLHttpReq = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) { // IE浏览器
  try {
  XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e){
  try {
  XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e) {}
  }
  }
  }

  //发送请求函数
  function addOrUpdatePermission(var field) {
  alert("hi"); //没有执行到这里
  createXMLHttpRequest();
  var url = "acl.do?method=addOrUpdatePermission&moduleId=" + field.moduleId + "&permission=" + field.permission + "&authorizationTypeId=" + field.authorizationTypeId + "&authorizationType=" + field.authorizationType;
  // 加随机数防止缓存
if (url.indexOf("?") > 0)
{
url += "&randnum=" + Math.random();
}
else
{
url += "?randnum=" + Math.random();
}
// 设定请求编码方式
  setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  XMLHttpReq.open("GET", url, true);
  XMLHttpReq.onreadystatechange = processResponse;//指定响应函数
  XMLHttpReq.send(null); // 发送请求
  }

  // 处理返回信息函数
  function processResponse() {
  if (XMLHttpReq.readyState == 4) { // 判断对象状态
  if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息
  alert("添加了");
  DisplayHot();
  //setTimeout("sendRequest()", 1000);
  } else { //页面不正常
  window.alert("您所请求的页面有异常。");
  }
  }
  }

  // 显示更新数据信息的函数___
  function DisplayHot(){
  }
   
  function hello(){
  alert("hi");
  }
</script>
<body>
<div align="center"><br>
<c:if test="${aclForm.authorizationType eq 'User'}">
  <font size="4" >请给用户[<font color="red">${person.name }</font>]授权</font>
  </c:if>
  <c:if test="${aclForm.authorizationType eq 'Role'}">
  <font size="4" >请给角色[<font color="red">${role.name }</font>]授权</font>


  </c:if>
  </div>
  <table width="600" border="0" cellPadding="0" cellSpacing="1" bgcolor="#6386d6">
  <!-- 列表标题栏 -->
<tr bgcolor="#EFF3F7" class="TableBody1">
<td width="20%" height="37" align="center"><b>一级模块</b></td>
<td width="20%" height="37" align="center"><B>二级模块</B></td>
<td width="30%" height="37" align="center"><b>授权</b></td>
<c:if test="${aclForm.authorizationType eq 'User'}">
<td width="15%" height="37" align="center"><b>继承</b></td>
</c:if>
 
<td width="15%" height="37" align="center"><b>启用</b></td>
  </tr>
  <!-- 列表数据栏 -->
<c:if test="${!empty modules}">
<c:forEach items="${modules }" var="module">
<tr bgcolor="#EFF3F7" class="TableBody1" onmouseover="this.bgColor = '#DEE7FF';" onmouseout="this.bgColor='#EFF3F7';">
<td align="center" vAlign="center">${module.name }</td>
<td align="center" vAlign="center"></td>
<td align="center" vAlign="center">
C<input type="checkbox" id="${module.id }_C" moduleId="${module.id }" 
AuthorizationType="${aclForm.authorizationType }" 
authorizationTypeId="${aclForm.authorizationTypeId }" 
permission="0"
onclick="addOrUpdatePermission(this)" > 
R<input type="checkbox" id="${module.id }_R" moduleId="${module.id }" 
AuthorizationType="${aclForm.authorizationType }" 
authorizationTypeId="${aclForm.authorizationTypeId }"
permission="1" 
onclick="addOrUpdatePermission(this)"> 
U<input type="checkbox" id="${module.id }_U" moduleId="${module.id }" 
AuthorizationType="${aclForm.authorizationType }" 
authorizationTypeId="${aclForm.authorizationTypeId }"
permission="2" 
onclick="addOrUpdatePermission(this)"> 
D<input type="checkbox" id="${module.id }_D" moduleId="${module.id }" 
AuthorizationType="${aclForm.authorizationType }" 
authorizationTypeId="${aclForm.authorizationTypeId }"
permission="3" 
onclick="alert('hi')"> 
</td>
<c:if test="${aclForm.authorizationType eq 'User'}">
<td align="center" vAlign="center"><input type="checkbox" id="${module.id }_EXT"></td>
</c:if>
<td align="center" vAlign="center"><input type="checkbox" id="${module.id }START"></td>
</tr>
<c:forEach items="${module.children}" var="children">
<tr bgcolor="#EFF3F7" class="TableBody1" onmouseover="this.bgColor = '#DEE7FF';" onmouseout="this.bgColor='#EFF3F7';">
<td align="center" vAlign="center"></td>
<td align="center" vAlign="center">${children.name }</td>
<td align="center" vAlign="center">


C<input type="checkbox" id="${children.id }_C" moduleId="${children.id }" onclick="addOrUpdatePermission(this)" permission="0"> 
R<input type="checkbox" id="${children.id }_R" moduleId="${children.id }" onclick="addOrUpdatePermission(this)" permission="1"> 
U<input type="checkbox" id="${children.id }_U" moduleId="${children.id }" onclick="addOrUpdatePermission(this)" permission="2"> 
D<input type="checkbox" id="${children.id }_D" moduleId="${children.id }" onclick="addOrUpdatePermission(this)" permission="3">
</td>
<c:if test="${aclForm.authorizationType eq 'User'}">
<td align="center" vAlign="center"><input type="checkbox" id="${children.id }_EXT"></td>
</c:if>
<td align="center" vAlign="center"><input type="checkbox" id="${children.id }_START"></td>
</tr>

</c:forEach>
</c:forEach>
</c:if><!--
  在列表数据为空的时候,要显示的提示信息 
--><c:if test="${empty modules}">
<tr>
<td colspan="5" align="center" bgcolor="#EFF3F7" class="TableBody1" onmouseover="this.bgColor = '#DEE7FF';" onmouseout="this.bgColor='#EFF3F7';"><!--
没有找到相应的记录
--></td>
</tr>
</c:if>
  </table>
   
</body>
</html>


[解决办法]
装个火狐浏览器,可以再错误控制台查看错误信息。。自己先看一下什么地方报错把。。
[解决办法]
script块只留那个函数
函数中只留一个alert测试
[解决办法]

探讨
先说一下,我是想但选择checkbox的时候,调用javascript里面定义的函数
但是却不能进入函数
而我在onclick上面添加alert的时候却是可以响应的
这是为什么,麻烦各位高手们指点下!谢谢
代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="U……

热点排行