蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 |
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程


    

蓝森林 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]




Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com