怎样用简单的办法,让链接实现按钮相同的效果:根据onsubmit()返回值,调用submit()?
如下示例代码:
<script>
function os(form){
alert( "validate ");
return true;
}
</script>
<form action= " " onsubmit= "os(this) ">
<input type=input>
<input type=submit>
<a href= "# " onclick= "submit() "> submit </a>
</form>
当onclick= "submit() "时,点击链接不会调用onsubmit()方法。
而当onclick= "onsubmit() "时,点击链接又不会调用submit()方法提交表单。
试过onclick= "if(onsubmit()) submit(); "也不成功,因为这时onsubmit()的返回值居然是undefined!(虽然会调用os()方法)
另外,我不希望是onclick= "if(os(...)) submit() ",因为我想在所有表单中,都使用相同的写法。
------解决方案--------------------直接onclick= "onsubmit();submit(); "不行吗
------解决方案--------------------不用onclick,直接用onsubmit= "function() "
------解决方案--------------------他是a,当然不会提交了
<script>
function os(form){
alert( "validate ");
form.submit();
return true;
}
</script>
<form action= " " onsubmit= "os(this) ">
<input type=input>
<input type=submit>
<a href= "# " onclick= "onsubmit() "> submit </a>
</form>