jQueryselect重置
我使用Jquery Chosen插件的窗体中有一堆select元素。 我怎样才能重置表单? 以下不起作用: 
 <input type="reset" /> 
	
 您需要重置字段的值,然后触发input中的liszt:updated事件来更新它,我在这里做了一个小例子。 
 $(".chzn-select").chosen(); $('a').click(function(){ $(".chzn-select").val('').trigger("liszt:updated"); }); 
从v1.0发布以来,触发器现在被称为“select:更新”。 任何使用这个新版本的人都需要使用触发更新
 $(".chosen-select").val('').trigger("chosen:updated"); 
从v1.0发布以来,触发器现在被称为“select:更新”。 任何使用这个新版本的人都需要使用触发更新
 $(".chosen-select").val('').trigger("chosen:updated"); 
你可以试试这个:
 $('select').chosen('destroy'); $('select').prop("selectedIndex", -1); $('select').chosen(); 
为了有复位的工作自然使用这个:
 $("input[type='reset'], button[type='reset']").click(function(e){ e.preventDefault(); var form = $(this).closest('form').get(0); form.reset(); $(form).find('select').each(function(i, v) { $(v).trigger('chosen:updated'); }); } 
以前的选项都不适合我。 我不得不这样做,就像旧学校,甚至使用一些原生的JavaScript,这里是代码:
 $('#dllSample option').each(function(){ $(this)[0].selected = false; }); $("#dllSample").trigger("chosen:updated"); 
有时你必须重新设置被选中的select。
我这样做
 jQuery.fn.chosen_reset = function(n){ $(this).chosen('destroy'); $(this).prop('selectedIndex', 0); $(this).chosen(n) } 
然后像这样调用这个函数,并将这个选项作为参数
 $('select').chosen_reset({width:'369px'}); 
 为了更轻松自由的方法…假设您的input是在<form>标签内: 
 <form> <!-- your selects go here and any other input fields --> <input type="reset" value="Reset"> </form> 
这是我会做的:
 $("input[type='reset'], button[type='reset']").click(function(e){ setTimeout(function(){ $("select").trigger("chosen:updated"); }, 50); }); 
在这里看小提琴 。
在jQuery这样的事情应该工作
 <input name="Text1" id="something" type="text"> <input type="reset" id="reset_me"/> $("#reset_me").click(function() { $("#something").val(""); });