You'll need to reset the value of the field, then trigger the liszt:updated event on the input to get it to update, ive made a fiddle with a working example here.
//Gets the selected values
var selected = [];
for (var option of document.getElementById('mySelect').options) {
if (option.selected) {
selected.push(option.value);
}
}
//Resets the form
document.getElementById('form1').reset();
//Chosen values doesnt get reset, so we do this manually
//Removes the values selected by clicking on the x icon
$link = $('a.search-choice-close');
var i;
for (i = 0; i < selected.length; i++) {
$link[i].click();
}
None of the answers here worked for me.
Im using chosen select with the multiple attribute.
Normal submit form button didnt do the trick either.
So i just had a function do this upon click.
//Gets the selected values
var selected = [];
for (var option of document.getElementById('mySelect').options) {
if (option.selected) {
selected.push(option.value);
}
}
//Resets the form
document.getElementById('form1').reset();
//Chosen values doesnt get reset, so we do this manually
//Removes the values selected by clicking on the x icon
$link = $('a.search-choice-close');
var i;
for (i = 0; i < selected.length; i++) {
$link[i].click();
}
发布评论
评论(10)
您需要重置字段的值,然后在输入上触发 liszt:updated 事件以使其更新,我在这里做了一个工作示例。
http://jsfiddle.net/VSpa3/3/
自发布以来选择的 v1.0 触发器现在称为“选择:更新”。使用此新版本的任何人都需要使用以下命令触发更新
You'll need to reset the value of the field, then trigger the
liszt:updated
event on the input to get it to update, ive made a fiddle with a working example here.http://jsfiddle.net/VSpa3/3/
Since the release of chosen v1.0 the trigger is now called 'chosen:updated'. Anyone using this new version needs to trigger the update using
自 selected v1.0 发布以来,触发器现在称为“chosen:updated”。使用此新版本的任何人都需要使用以下命令触发更新
Since the release of chosen v1.0 the trigger is now called 'chosen:updated'. Anyone using this new version needs to trigger the update using
你可以试试这个:
You could try this:
为了自然地重置工作,请使用以下命令:
in order to have reset working naturally use this:
之前的选项都不适合我。我必须像老派那样做,甚至使用一些本机 JavaScript,代码如下:
None of the previous options work for me. I had to do it like the old school, even using some native javascript, here is the code:
这对我有用
This worked for me
对于更轻松的方法...假设您的输入位于
这就是我要做的:
请参阅 在这里摆弄。
For a more hassle free approach...assuming your inputs are inside
<form>
tags:This is what I would do:
See fiddle here.
这里的答案都不适合我。
我使用带有 multiple 属性的选择选择。
普通的提交表单按钮也不起作用。
所以我只是有一个函数在点击时执行此操作。
None of the answers here worked for me.
Im using chosen select with the multiple attribute.
Normal submit form button didnt do the trick either.
So i just had a function do this upon click.
有时您必须重置所选择的被调用的选择。
我这样做
并像这样调用这个函数,并将选项作为参数
Sometimes you have to reset the select that chosen is called on.
I do this
And call this function like this, with the options as an argument
在 jQuery 中,类似的东西应该可以工作
In jQuery something like this should work