javascript - dynamically add new option in jquery chosen plugin where select multiple - Stack Overflow

I am using choose master Example<select data-placeholder="Click to Select Role..." style=

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 badges
Add a ment  | 

3 Answers 3

Reset to default 4

After 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");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745463174a4628799.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信