|
蓝森林 http://www.lslnet.com 2006年8月25日 8:28
javascript中如何激发多个事件?急~
function yanzheng()
{
if(document.form1.userName.value=="")
{
alert('请输入用户名');
}
}
function clear1()
{
document.form1.userName.value="";
document.form1.userPwd.value="";
}
<form name="form1" action="yanz.aspx" method="post">
<a href="#" onclick="yanz()">
<img src="images/user01_img/zhuci_as2.gif" width="70" height="22" border="0" onclick="document.form1.submit()"></a>
</form>
因为按钮为图片,我用FROM提交不了....改为onclick="document.form1.submit(),但同时又想激发验证事件,....... |
如果你的form没有onsubmit事件
<form action="http://google.com">
<a href="#" onclick="this.parentNode.submit();return false;">aa</a>
</form>
如果有onsubmit事件,则要根据你的具体情况修改了,比如你的onsubmit事件只是执行一些js语句,并没有return语句,则
<form onsubmit="alert('马上就要提交了哦!')" action="http://google.com">
<input name="xx">
<a href="#" onclick="this.parentNode.onsubmit();this.parentNode.submit();return false;">aa</a>
</form>
否则,则类似
<form onsubmit="return confirm('真的要提交吗?')" action="http://google.com">
<input name="xx">
<a href="#" onclick="if (this.parentNode.onsubmit()){this.parentNode.submit()};return false;">aa</a>
</form>
注:onsubmit()这种写法只有ie支持 |
[html]
<script>
function yanzheng()
{
if(document.form1.userName.value=="")
{
alert('请输入用户名'); return(false);
}
return(true);
}
function clear1()
{
document.form1.userName.value="";
document.form1.userPwd.value="";
}
</script>
<form name="form1" action="yanz.aspx" method="post">
<input name="userName" />
<img src="images/user01_img/zhuci_as2.gif" width="70" height="22" border="0" onclick="if(yanzheng())document.form1.submit()"></a>
</form>
[/html] |
|