Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Asmselect并使用Javascript更改选项的选定状态_Jquery_Dynamic_Selected_Asmselect - Fatal编程技术网

Jquery Asmselect并使用Javascript更改选项的选定状态

Jquery Asmselect并使用Javascript更改选项的选定状态,jquery,dynamic,selected,asmselect,Jquery,Dynamic,Selected,Asmselect,我试图在asmselect中完成一项相当简单的任务,但运气不佳 我有一个使用asmselect的多选列表。最初未选择任何选项 <select multiple="multiple" id="myselectdiv" name="myselectdiv[]" title="choose"> <option value="0">zero</option> <option value="1">one</option> <option v

我试图在asmselect中完成一项相当简单的任务,但运气不佳

我有一个使用asmselect的多选列表。最初未选择任何选项

<select multiple="multiple" id="myselectdiv" name="myselectdiv[]" title="choose">
<option value="0">zero</option>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
当我尝试在多重选择列表上执行此操作时,asmselect已初始化,但什么也没有发生。我希望javascript选择该项并将其显示在下面,就像使用asmselect手动单击该项一样


Safari 5和Firefox 21、MacOS上也存在同样的问题。感谢您的帮助。

经过一些实验,我终于解决了这个问题。我正在发布解决方案,以防有人遇到同样的问题

文档描述在加载文档时初始化asmSelect,例如:

$(document).ready(function() {
   $("select[multiple]").asmSelect({
   addItemTarget: 'bottom',
   animate: true,
   highlight: true,
   sortable: true
   });          
}); 
function something() {
   [do some ajax]

   // remove the asmSelect attachment to the select list
   $(".asmSelect").remove(); $(".asmList").remove();

   //change some selections in the list with Javascript
   document.getElementById('myselectlist').options[3].selected=true;

   // re-initialize asmSelect
   $(document).ready(function() {
     $("select[multiple]").asmSelect({
     addItemTarget: 'bottom',
     animate: true,
     highlight: true,
     sortable: true
     });            
   }); 
}
但是,如果您计划使用javascript动态填充和/或更改所选项目,则在页面加载后,需要在进行更改时取消对asmSelect的初始化,然后重新初始化。例如:

$(document).ready(function() {
   $("select[multiple]").asmSelect({
   addItemTarget: 'bottom',
   animate: true,
   highlight: true,
   sortable: true
   });          
}); 
function something() {
   [do some ajax]

   // remove the asmSelect attachment to the select list
   $(".asmSelect").remove(); $(".asmList").remove();

   //change some selections in the list with Javascript
   document.getElementById('myselectlist').options[3].selected=true;

   // re-initialize asmSelect
   $(document).ready(function() {
     $("select[multiple]").asmSelect({
     addItemTarget: 'bottom',
     animate: true,
     highlight: true,
     sortable: true
     });            
   }); 
}
总的来说,我对asmSelect非常满意,我希望这篇文章对其他实现该工具的人有所帮助