function checkModify(){
var count = 0;
var j = 0;
for(var i = 0;i < document.getElementsByName("selectFlag").length;i++){
if(document.getElementsByName("selectFlag")[i].checked){
count++;
j = i;
}
}
if(count == 0){
alert("您还未选择需要修改的用户");
return;
}
if(count > 1){
alert("一次只能修改一个用户");
return;
}
if(count == 1){
window.self.location = "${pageContext.request.contextPath}/jsp/List.do?command=ListById&wuLiaoId=" + document.getElementsByName("selectFlag")[j].value + "&pageNo=${myList.pageNo }&pageSize=${myList.pageSize}&queryStr=${myList.queryStr }";
}
}当count==0或>1,弹出对话框后,会怎么样,return;执行后会怎么样我是这样调用这个function的:<input type="submit" value="修改" onClick = "checkModify()">
我每次按钮点下去,不管有没有选中,我按下alert的按钮后它就跳转了,而且还跳到莫名其妙的地址http://localhost:8080/WuLiao/jsp/method="post"?
var count = 0;
var j = 0;
for(var i = 0;i < document.getElementsByName("selectFlag").length;i++){
if(document.getElementsByName("selectFlag")[i].checked){
count++;
j = i;
}
}
if(count == 0){
alert("您还未选择需要修改的用户");
return;
}
if(count > 1){
alert("一次只能修改一个用户");
return;
}
if(count == 1){
window.self.location = "${pageContext.request.contextPath}/jsp/List.do?command=ListById&wuLiaoId=" + document.getElementsByName("selectFlag")[j].value + "&pageNo=${myList.pageNo }&pageSize=${myList.pageSize}&queryStr=${myList.queryStr }";
}
}当count==0或>1,弹出对话框后,会怎么样,return;执行后会怎么样我是这样调用这个function的:<input type="submit" value="修改" onClick = "checkModify()">
我每次按钮点下去,不管有没有选中,我按下alert的按钮后它就跳转了,而且还跳到莫名其妙的地址http://localhost:8080/WuLiao/jsp/method="post"?
<input type="button" value="修改" onClick = "checkModify()">
submit一般都会返回true或false
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript">
function checkModify(){
var count = 0;
var j = 0;
for(var i = 0;i < document.getElementsByName("selectFlag").length;i++){
if(document.getElementsByName("selectFlag")[i].checked){
count++;
j = i;
}
}
if(count == 0){
alert("您还未选择需要修改的用户");
return;
}
if(count > 1){
alert("一次只能修改一个用户");
return;
}
if(count == 1){
window.self.location = "${pageContext.request.contextPath}/jsp/List.do?command=ListById&wuLiaoId=" + document.getElementsByName("selectFlag")[j].value + "&pageNo=${myList.pageNo }&pageSize=${myList.pageSize}&queryStr=${myList.queryStr }";
}
}
</script>
<title>TEST</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
test1<input type="checkbox" name="selectFlag" id="1" />
test2<input type="checkbox" name="selectFlag" id="2" />
<input type="submit" value="修改" onClick = "checkModify()">
</form>
</body>
</html>在FF下测试过了,没有问题的.你看看是不是你那里弄错了?我把我的测试代码全贴出来了,你试试吧!
其执行提交,如果你想在提交之前执行检查,应该通过form的onsubmit还触发
而且格式必须是onsubmit="return FuncName();".否则会提交到你的action制定
的页面你没有指定所以会提交到自身也就是http://localhost:8080/WuLiao/jsp/method="post"<form id="form1" name="form1" method="post" action="" onsubmit="return checkModify();">
test1 <input type="checkbox" name="selectFlag" id="1" />
test2 <input type="checkbox" name="selectFlag" id="2" />
<input type="submit" value="修改">
</form>
<input type="submit" onclick="return aaa()" value="submit">
</form>
<script language="javascript">
function aaa(){
return false;
}
</script>大家试试看.