Javascript:在firefox上以奇怪的行为输入输入元素

Javascript:在firefox上以奇怪的行为输入输入元素,javascript,jquery,firefox,input,Javascript,Jquery,Firefox,Input,我有一个带有select、button和input元素的html表单 <form action=""> <button>innocent button</button> <select multiple name="multiple"> <option selected value="a">A</option> <option value="b">B</option>

我有一个带有select、button和input元素的html表单

<form action="">
    <button>innocent button</button>
    <select multiple name="multiple">
    <option selected value="a">A</option>
    <option value="b">B</option>
</select>
<input style="width:300px" type="text" value="press here enter and look at the multiple select" name="" />
</form>
演示:在此处尝试:

在Chrome上一切正常。 但在Firefox上: 如果在输入字段中按ENTER键,则“选择”元素将丢失其选定内容


Firefox有什么问题?

当您在输入上按enter键时,您实际上是在触发按钮的click事件,尝试将conole.log放入其中,您会看到它启动

您可以通过以下方式停止提交:

然后在表单中添加按键事件

    <form onkeypress="return stopSubmit(event)">


查看

当您在输入上按enter键时,您实际上触发了按钮的click事件,尝试将conole.log放入其中,您将看到它触发

您可以通过以下方式停止提交:

然后在表单中添加按键事件

    <form onkeypress="return stopSubmit(event)">


请参见

我想,我通过添加属性类型和值按钮修复了它


我想,我通过添加属性类型和值按钮修复了它


正在提交表单,您将看到页面刷新。同样的事情也会发生在其他浏览器中,如Safari。+1对于innocent Button,表单正在提交,您将看到页面刷新。同样的事情也会发生在其他浏览器中,如Safari。innocent button为+1,我如何防止在按钮上触发单击事件?@christianhaller也许我没有达到您的目标,但您的表单仍在提交中(FF15/Win)我怎样才能防止在按钮上触发点击事件?@christianhaller也许我没有达到你的目标,但你的表格仍在提交中(FF15/Win)也许我没有达到你的目标,但你的表格仍在提交中(FF15/Win),在输入元素中按enter键之后,表单提交之前,元素正在更改其值。可能我在这里没有达到您的目标,但您的表单仍在提交中(FF15/Win),在输入元素中按enter键之后,表单提交之前,元素正在更改其值。
    <form onkeypress="return stopSubmit(event)">