Javascript 单击页面的关闭按钮,我想清除所有selectbox值
我的页面上有3个选择框,单击“关闭”按钮后,我想清除类Javascript 单击页面的关闭按钮,我想清除所有selectbox值,javascript,jquery,reactjs,Javascript,Jquery,Reactjs,我的页面上有3个选择框,单击“关闭”按钮后,我想清除类.popup下的所有选择框 下面是我清除字段的代码 clearText: function() { $('.popupBody input').val(''); $('.popupBody select').val(''); $('.popupForm').find('.errmsgActive').removeClass('errmsgActive'); $('.popupForm').find('.errm
.popup
下的所有选择框
下面是我清除字段的代码
clearText: function() {
$('.popupBody input').val('');
$('.popupBody select').val('');
$('.popupForm').find('.errmsgActive').removeClass('errmsgActive');
$('.popupForm').find('.errmsg').html('');
}
为了清除.popubody
类中的所有选择框,我使用下面的代码
$('.popupBody select').val('');
你的代码看起来不错。。显然
$('.popubody select').val('')
是清除.popubody
下选择下拉列表的值
但是
确保所有选择输入必须具有选项值='
请参阅下面的代码
$(“.popubody select”).select2();
$(“#清除”)。单击(函数(){
$('.popubody select').val('-1').change();
})
@import”https://select2.github.io/dist/css/select2.min.css";代码>
挑选
A.
B
C
挑选
A1
地下一层
C1
挑选
A2
地下二层
C2
清除
要重置下拉列表,您需要选择默认元素,通常是第一个元素:
$('.popupBody select').find('option:first-child').attr('selected','selected');
要在中重置值,请选择2使用
$('.popupBody select').select2("val", "");
试试这个,这个对你有用
选择选项一
--挑选--
选择1值1
选择1值2
选择1值3
选择选项二
--挑选--
选择2值1
选择2值2
选择2值3
选择选项三
--挑选--
栈溢出
是
令人惊叹的
$(文档).ready(函数(){
$(“#关闭按钮”)。单击(函数(){
$(“div.popubody select”).val(“”);
});
});
要清除在select2
选择框中所做的选择,您可以尝试以下方法:
$('.popupBody select').each(function(){
//iterate over all the select boxes one by one
$(this).select2("val", ""); //clearing the selection made
});
通过清除一个select来放置HTML文件我希望您的意思是将select返回到默认值实际上我正在使用selectTo插件。@KalashirselectTo
或select2
插件?请确认。我正在使用selectTo插件,并且defalut选项具有value=“-1”我已尝试此$('.popubody select')。查找('option:first child')。attr('selected','selected');这是将值设置为默认值,但选择框未被清除。很抱歉,其select 2 jquery pluginI已尝试此$('.popubody select')。查找('option:first child')。attr('selected','selecte')d');这是将值设置为默认值,但选择框未被清除。选择框设置为默认值,但仍显示所选国家/地区。