Javascript 在多个选择框之间移动项目
我有两个多重选择,即。mySelectNumberTest1和mySelectNumberTest2。我想做的是能够在第一个下拉列表中选择项目,当我单击复选框/按钮或任何将触发事件的控件时,它应该从mySelectNumberTest1中获取选项并将其填充到mySelectNumberTest2中 我遵循了这个链接:它部分解决了我的问题。唯一缺少的是,如果在mySelectNumberTest1中选择多个项目,它将只获取第一个项目并将其填充到mySelectNumberTest2中 下面的代码仅在我将select中的项目填充到普通输入文本框中时有效Javascript 在多个选择框之间移动项目,javascript,html,angularjs,Javascript,Html,Angularjs,我有两个多重选择,即。mySelectNumberTest1和mySelectNumberTest2。我想做的是能够在第一个下拉列表中选择项目,当我单击复选框/按钮或任何将触发事件的控件时,它应该从mySelectNumberTest1中获取选项并将其填充到mySelectNumberTest2中 我遵循了这个链接:它部分解决了我的问题。唯一缺少的是,如果在mySelectNumberTest1中选择多个项目,它将只获取第一个项目并将其填充到mySelectNumberTest2中 下面的代码仅
<select id="mySelectNumberTest1" name="mySelectNumberTest" multiple="multiple">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<input type="checkbox" id="tickHereToMove" />
<input id="mySelectNumberTest2" name="mySelectNumberTest2" type="text" onchange="copyTextValueTest(this);" />
function copyTextValueTest(bf) {
var e = document.getElementById("mySelectNumberTest1");
var strUser = e.options[e.selectedIndex].text;
document.getElementById("mySelectNumberTest2").value = strUser;
alert(strUser);
}
这种方法在连接文本时也存在一些问题。我尝试了.split函数,但仍然没有得到我想要的结果。我想要我的SelectNumberTest2上每一行中的所选项目
这个图书馆正是我想做的。我在一个Angular JS项目中工作,当我尝试在index.html页面中包含jquery脚本时,它会导致异常行为,并扰乱页面的样式
因此,如果我在mySelectNumberTest1中选择1和3,它应该在mySelectNumberTest2的两行中填充它,而不是12行
如果这可以通过拖放实现,我也会很高兴 只需这样做:
函数addOptions fromId,toId{
var fromEl=document.getElementById fromId,
toEl=document.getElementById toId;
如果fromEl.selectedIndex>=0{
var指数=toEl.options.length;
对于变量i=0;i