checkbox不能用onclick事件??

qingwangyoucao 2009-10-15 08:57:44
在jsp页面输出xml文件,有如下代码
function writeTree(xmlDom){
//首先获取一级节点
var functions = xmlDom.getElementsByTagName("firstSort");
var id = "<table class='tab_grid' border='0'><tr><td colspan='4'><div>";
id += "   <a href='javascript:clearCheck();' style='color:red;'>清空所有选择</a>   <a href='javascript:saveid();' style='color:red;'>提交</a></div></td></tr>";
for(var i=0; i<functions.length; i++){
id += "<tr><td colspan='4'>";
id += "<b>"+ functions[i].getAttribute("sort") +"</b>\n";
id += "</td></tr>";
if(functions[i].hasChildNodes){//判断一级节点下是否有子节点
for(var n=0; n<functions[i].childNodes.length; n++){
id += "<tr><td colspan='4'>   ";
//存放二级节点
var child = functions[i].childNodes.item(n);
if(child.hasChildNodes){//判断二级节点下是否有子节点,如果有三级节点,就获取三级节点的ID
id += "<b>"+ child.getAttribute("sort");
id += "</b></td></tr>";
id += "<tr><td colspan='4'>      ";
for(var h=0; h<child.childNodes.length; h++){
var smallchild = child.childNodes.item(h);
id += "<input type='checkbox' id='"+ smallchild.getAttribute("id") +"' value='"+ smallchild.getAttribute("id") +"' onclick=test();/> "; id += smallchild.getAttribute("sort");
if(smallchild.getAttribute("point")!=null || smallchild.getAttribute("point")!=''){
id += " <font style='color:red'>";
id += smallchild.getAttribute("point");
id +="分</font>";
}
}
id += "</td></tr>";
}else{ //否则获取二级节点的ID
id += "<input type='checkbox' id='"+ child.getAttribute("id") +"' value='"+ child.getAttribute("id") +"' onclick='alert('"+ child.getAttribute("id") +"')'/> "; id += child.getAttribute("sort");
if(child.getAttribute("point")!=null || child.getAttribute("point")!=''){
id += " <font style='color:red'>";
id += child.getAttribute("point");
id +="分</font>";
}
id += "</td></tr>";
}
}
}

}
id += "</table>";
document.getElementById("sortdiv").innerHTML = id;

}

提示语法错误,问题出在onclick事件处,如果取消该事件,页面不提示语法错误。测试简单的输出也不行。

原来用onclick事件是没有问题的,调用test方法并且传了一个参数没有问题。 后来为test方法添加了一个参数,就不可以使用。
求解。。。
...全文
615 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
connor_zheng 2009-10-15
  • 打赏
  • 举报
回复
onclick='alert(1234556);'测试哈就知道了
淡定的峰哥 2009-10-15
  • 打赏
  • 举报
回复
onclick='test();'
hanke209 2009-10-15
  • 打赏
  • 举报
回复
试试:
id += " <input type='checkbox' id='"+ child.getAttribute("id") +"' value='"+ child.getAttribute("id") +"onclick='alert('"+ child.getAttribute("id") +"')/> ";
caowenzhouzx 2009-10-15
  • 打赏
  • 举报
回复
hehe,查API撒
笨沙发 2009-10-15
  • 打赏
  • 举报
回复
' onclick='
改成
' onc' + 'lick='
看下

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧