admin管理员组文章数量:1426066
I am using choose master /
Example
<select data-placeholder="Click to Select Role..." style="width:200px;" id="geoRange" name="geoRange" class="chzn-select" tabindex="8" multiple>
<option value="1">England</option>
</select>
I am adding new option in this select
$('#geoRange').append( new Option('USA',2) );
It is not working
How can I add new option?
I am using choose master http://harvesthq.github./chosen/
Example
<select data-placeholder="Click to Select Role..." style="width:200px;" id="geoRange" name="geoRange" class="chzn-select" tabindex="8" multiple>
<option value="1">England</option>
</select>
I am adding new option in this select
$('#geoRange').append( new Option('USA',2) );
It is not working
How can I add new option?
Share Improve this question edited Jul 27, 2015 at 8:04 Dimitri Dewaele 10.7k21 gold badges83 silver badges130 bronze badges asked Dec 30, 2012 at 10:14 Shahid GhafoorShahid Ghafoor 3,11318 gold badges73 silver badges126 bronze badges3 Answers
Reset to default 4After updating the select list, you apparently need to also notify Chosen that you did that.
$("#geoRange").trigger("liszt:updated");
I haven't used Chosen myself (using Select2 instead), but that's what the docs say. See http://harvesthq.github./chosen/
<script type="text/javascript">
function fnc()
{
var select1 = document.getElementById("geoRange");
select1.options[select1.options.length] = new Option('USA', 2);
}
</script>
</head>
<body>
<select data-placeholder="Click to Select Role..." style="width:200px;" id="geoRange" name="geoRange" class="chzn-select" tabindex="8" multiple>
<option value="1">England</option>
</select>
<input type="button" onclick="fnc()" value="click me" />
$('#geoRange').append( new Option('USA',2) );
The following statement solve my problem
$("#geoRange").trigger("liszt:updated");
本文标签: javascriptdynamically add new option in jquery chosen plugin where select multipleStack Overflow
版权声明:本文标题:javascript - dynamically add new option in jquery chosen plugin where select multiple - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745463174a2659415.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论