<script>
function postFun(){
if(){
return true;
}else{
return false
}
}
</script>
<form name="form1" onsubmit="return postFun()">
function postFun(){
if(){
return true;
}else{
return false
}
}
</script>
<form name="form1" onsubmit="return postFun()">
1.<input type=submit >submit按钮<br>
2.<input type=text>当form中只有一个文本本框按回车的时候<br>
3.<input type=button onclick=javascript:form1.submit()>自己写脚本提交<br>
</form>前两种是可以触发 onsubmit事件的,但是第三种不行。
document.forms[0].submit();
function submit(){
//你要写的提交触发事件
return false;
}
document.all.form1.submit=submit;
类似于写一个js报错的页面 report_error(msg,url,line){}; self.onerror=report_error;
document.all.form1.submit=submit;
类似于写一个js报错的页面 report_error(msg,url,line){}; self.onerror=report_error;====================================================那我能不能在原有的form1.submit前面加一段自己的代码呢?
//<![CDATA[
function test(oFm){
try{oFm.onsubmit()}catch(e){}
alert('addition');
}
//]]>
</script>
<form id='t' onsubmit="alert('ok')"">
<button onclick="test(document.getElementById('t'));">go...</button>
</form>
你说的第3行不行,那是因为代码写错了.
onclick是没有javascript的.只是用在href中的.