Javascript 选择js的麻烦
我正在使用lib:Javascript 选择js的麻烦,javascript,jquery-chosen,Javascript,Jquery Chosen,我正在使用lib: ... 然后我需要更改此选择元素: $("#country").append('<option value="'+ countryid +'">' + countryname + '</option>'); $(“#国家”)。追加(“”+countryname+“”); 但它不适用于此库,也不适用于此库。 我怎么能修好它? 谢谢 通过使用下面的代码,您可以实现您的目标 var current
...
然后我需要更改此选择元素:
$("#country").append('<option value="'+ countryid +'">' + countryname + '</option>');
$(“#国家”)。追加(“”+countryname+“”);
但它不适用于此库,也不适用于此库。
我怎么能修好它?
谢谢 通过使用下面的代码,您可以实现您的目标
var currentelement=document.querySelector(“#country”);
var newOptionElement=document.createElement(“选项”);
newOptionElement.text=“测试”;
currentelement.add(newOptionElement);
var newOptionElement=document.createElement(“选项”);
newOptionElement.text=“Test1”;
currentelement.add(newOptionElement);
var newOptionElement=document.createElement(“选项”);
newOptionElement.text=“Test2”;
currentelement.add(newOptionElement)代码>
编辑元素后,我必须使用此代码,它可以工作可能的重复,但为什么我不能使用jquery?您可以像这样使用jquery方法$(“#国家”).append(新选项(“选项文本”、“值”)代码>
$("#country").append('<option value="'+ countryid +'">' + countryname + '</option>');
$("#form_field").trigger("chosen:updated");