我有一个选择,按钮和输入元素的HTML表单。Javascript:在输入元素中输入与Firefox上的奇怪行为
<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>
和一些jQuery的JavaScript的
$(document).ready(function(){
console.log('hi');
var $button = $('button');
$button.on('click',function(e){
$('select option').first().attr('selected',false);
e.preventDefault();
});
演示:在这里试试吧: http://jsfiddle.net/3Rjdh/
在Chrome一切正常。 但在Firefox上: 如果在输入字段中按ENTER,则选择元素将失去选择。
Firefox有什么问题?
被提交的表格,你看到刷新页面添加的属性类型固定它。在Safari等其他浏览器中也会发生同样的情况。 – RobG
+1 for _innocent button_ – undefined