在Mozilla Firefox中设置下拉列表的空值不起作用
问题描述:
我正在尝试将下拉列表的默认值设置为空;即没有选择任何价值。
$ dropdown.prop(" selectedIndex",-1);
它适用于IE和Chrome,但在Firefox中不起作用。在Firefox中,它总是将下拉列表的第一个值设置为默认值。
我使用的是Mozilla版本23.0.1。
I am trying to set the default value of a drop down as empty; ie not selecting any value.
$dropdown.prop("selectedIndex", -1);
It works in IE and chrome, but doesn't work in Firefox. In Firefox, it always set the first value of the drop down as default value.
I am using Mozilla version 23.0.1.
答
dropdown.prop(" selectedIndex",-1);
它适用于IE和Chrome,但不起作用在Firefox中。在Firefox中,它总是将下拉列表的第一个值设置为默认值。
我使用的是Mozilla版本23.0.1。
dropdown.prop("selectedIndex", -1);
It works in IE and chrome, but doesn't work in Firefox. In Firefox, it always set the first value of the drop down as default value.
I am using Mozilla version 23.0.1.
尝试以下JQuery代码:
Try the following JQuery codes:
//with single quotes
dropdown.prop(' selectedIndex' , - 1);
// 或attr
dropdown.prop('selectedIndex', -1); //or with attr