简体   繁体   English

需要 select 在进行重置时选择所选选项

[英]need to select to choose the selected option in doing a reset

I am doing a reset and its working well for all fields except select我正在重置,并且它在除 select 之外的所有领域都运行良好

$("form").find("input[type=text] , textarea , select").each(function(){
          $(this).val('');

        });

not sure even in console inspect element, it shows selected but the actual element shows an empty select即使在控制台检查元素中也不确定,它显示已选中,但实际元素显示为空 select

In order to reset the select input, you can set the selectedIndex as follows:为了复位 select 输入,您可以设置selectedIndex如下:

$('select').prop('selectedIndex', 0);

Have you considered using $("form").reset() ?您是否考虑过使用$("form").reset()

That will use the default reset that comes with the browser这将使用浏览器附带的默认重置

You can even do <input type="reset" value="Reset" />你甚至可以做<input type="reset" value="Reset" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在HTML的选择/选项中选择选择的选项? - how to choose selected option in select/option in HTML? 重置选择选项的选定属性 - Reset selected attribut of select option 如何重置select2中的特定选定选项 - How to reset specific selected option in select2 选择特定选项时如何重置 select - How to reset select when a particular option is selected 选择从哪个事件委托处理程序的事件 <select>到所选<option> ? - What event(s) to choose to delegate a handler from <select> to the selected <option>? 怎么做 <select>元素不选择默认选择的第一个选项? - How to make <select> element not to choose first option as selected by default? 如何在JavaScript / jQuery中设置/重置先前选择的multi Select选项 - How to set/Reset the previously selected multi Select option in JavaScript/jQuery 如何重置所有输入并选择JavaScript中除选定选项之外的其他字段? - How to reset all input and select fields excluding selected option in JavaScript? 如何重置或设置为默认选择<option>在<select>关闭模态后 - How to reset or set to default selected <option> in <select> after closing the modal AngularJS select似乎需要匹配相同的对象来设置所选的选项 - AngularJS select seems to need to match on the same object to set the selected option
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM