[英]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.