日期:2014-05-16  浏览次数:20359 次

onlick触发多事件问题
<script   language= "JavaScript ">
function   funturn(){  
window.location.href= "voting.asp "}
</script>
<form   action= "a.asp "   method= "post "     target= "yincang "   >
<input   type= "radio "   name= "postvote "   value= "0 "   > 1号
<input   type= "radio "   name= "postvote "   value= "1 "   > 2号
<input   type= "submit "   name= "Submit "   value= "OK!提交! "   onclick=funturn()>

这个页面是包含在一个frameset里的,所以funturn是实现在另外一个frame里转向,但我现在要想加入对submit的验证,就是提交时先验证选的是哪个,如果是1号则弹出确认窗口(confirm):“确定选择1号?”用户点“确定”后再执行上面的那个funturn的函数,     选择2号同样这么做,而若没有选择则alert:“没有选择”,并且留在原页面,不进行funturn函数。

一个onclick触发这么多事我就不会了,大家帮帮忙。。

------解决方案--------------------
function funturn()
{
if(document.getElementsByName( "postvote ")[0].checked)
{
if(!confirm( "确定选择1号? ")) return;
}
else if(document.getElementsByName( "postvote ")[1].checked)
{
if(!confirm( "确定选择2号? ")) return;
}
else
{
alert( "没有选择 ");
return;
}
window.location.href= "voting.asp "
}
------解决方案--------------------
<html> <head> <title> abc </title>

</head>
<body>
<script language= "JavaScript ">
function funturn(){
postvoteobj = document.getElementsByName( "postvote ");
for (i=0;i <postvoteobj.length;i++)
{
if (postvoteobj[i].checked)
{
str = postvoteobj[i].value;
alert( "确定选择 "+str+ "? ");
window.location.href= "voting.asp ";
}
}
return false;
}
</script>
<form action= "a.asp " method= "post ">
<input type= "radio " name= "postvote " value= "1号 " > 1号
<input type= "radio " name= "postvote " value= "2号 " > 2号
<input type= "submit " name= "Submit " value= "OK!提交! " onclick= "return funturn(); ">
</body>
</html>
------解决方案--------------------
<form action= "a.asp " method= "post " target= "yincang " onsubmit= "return TestFunction() ">
...

FUNCTION TestFunction()
{
...//自己搞定
if (...)
return true;
if(...)
return false;
}

只要手动调用ONSUBMIT()函数就可以了。。。
------解决方案--------------------
對。。。。。返回true就會使用默認的動作。
------解决方案--------------------
支持  0009(夏天以南)