Opera中的HTML表单提交

时间:2008-11-27 12:42:57

标签: javascript html cross-browser opera

下面显示的HTML表单在Opera(版本:9.52)中无法正常工作。表单没有onsubmit属性,也没有type = submit的input元素。它只有两个输入元素type = button,并且两个onclick都调用一个js方法,我希望用户确认提交。如果我删除confirm()调用,它完全正常。在所有其他浏览器(FF2,FF3,IE7)中它运行正常。

任何指针?

<script type = "text/javascript">
function userSubmit(submitStatus)
{
    // Omitted code that uses the parameter 'submitStatus' for brevity
    if(confirm('Are you sure you want to submit?'))
        document.qpaper.pStatus.value = something;
    else
        return;     
    document.qpaper.submit();
}
</script>
<form  name = "qpaper" method = "post" action = "evaluate.page">
    <input name = "inp1" type = "button" value = "Do This" class = "formbutton" onClick = "userSubmit(false)">
    <input name = "inp2" type = "button" value = "Do That" class = "formbutton" onClick = "userSubmit(true)">
</form>

1 个答案:

答案 0 :(得分:2)

  1. 切勿使用document.nameofsomething。这是一种过时的技术,在21世纪的浏览器中提供了不完整的支持。对于表单,请使用document.forms.nameofform

  2. 不要使用onclick on按钮,除非你需要Javascript来表现不同,具体取决于按下了哪个按钮。如果您只想验证表单或确认提交,请改用<form onsubmit>

    <form onsubmit="return confirm('Sure?')">
    

    这样你甚至不需要form.submit()。如果<form onsubmit>返回false,则提交将被中止。

  3. 您甚至不需要找到该表格 <button onclick>形式为this.form <form onsubmit>表单中的this变量。

相关问题