jQuery表单和选择框

jQuery form and select box?

本文关键字:选择 表单 jQuery      更新时间:2023-09-26

我已经建立了一个使用3个选择框的表单,这些选择框是动态地一起使用的,当一个在使用时,另一个必须处于默认设置,这确保了选择框的任何动态事件都被关闭,到目前为止,我通过使用这个jquery完成了这一点:

$('form select').click(function() {
    $('form select').not(this).val('');
});

这做了我想在所有其他浏览器除了IE。

在其他浏览器中,它将其他选择输入返回到选择的最顶部选项,这意味着唯一的选择框是被选中的。但是,在IE中,它实际上完全删除了这个选项,让我留下一个空的选择框,直到它被点击!

有办法解决这个问题吗?

selectedIndex设置为0,而不是清除值:

$('form select').not(this).prop('selectedIndex', 0);

你可以试试这个

$('form select').click(function() {
    $('form select').not(this).each(function(){
        this.value='';
     });
});

try this

$('form select').not(this).children("option:selected").removeAttr("selected")