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");
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745463174a4628799.html
评论列表(0条)