Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.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
Javascript 无法读取属性';未定义';未定义的?如何将数字推送到第一个下拉列表?使用java脚本?_Javascript_Jquery - Fatal编程技术网

Javascript 无法读取属性';未定义';未定义的?如何将数字推送到第一个下拉列表?使用java脚本?

Javascript 无法读取属性';未定义';未定义的?如何将数字推送到第一个下拉列表?使用java脚本?,javascript,jquery,Javascript,Jquery,var select=document.getElementById(“源”); var select2=document.getElementById(“状态”); var期权=[“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”]; var期权2=[]; 函数moveright() { var a=source.options[source.selectedIndex].value; var option=document.createElement(“选项”); opt

var select=document.getElementById(“源”);
var select2=document.getElementById(“状态”);
var期权=[“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”];
var期权2=[];
函数moveright()
{
var a=source.options[source.selectedIndex].value;
var option=document.createElement(“选项”);
option.text=a;
选择2.添加(选项);
选择。删除(i);
}
函数moveleft()
{
var b=状态.option2[状态.selectedIndex].值;
var option2=document.createElement(“选项”);
选项2.text=b;
选择。添加(选项2);
选择2.删除(i);
}
对于(i=0;i

选择一个数字
选择一个数字

您只需将单击的
选择的
选项
附加到另一个。见下文:

if (event.currentTarget !== event.target)
已选中,因为我们不想移动选择本身。此外,您可能希望检查单击的选项是否为“选择一个数字”,但这取决于您自己

var select=document.getElementById(“selectNumber”);
var期权=[“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”];
对于(i=0;i

选择一个数字
选择一个数字
var firstSelect=document.getElementById(“selectNumber”);
var otherSelect=document.getElementById(“状态”);
var期权=[“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”];
对于(i=0;i
试试这个,移动数字时它也会对数字进行排序:

var select=document.getElementById(“selectNumber”);
var期权=[“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”];
对于(i=0;i$(b.text()?1:-1;});
optgroup.append(opts_列表);
optgroup.find('option')。单击(optionClicked);
选择值(已选择);
}


options.push(选择数字)
这里的
selectNumber
值是多少?您想做什么还不清楚。单击时是否希望数字移动到第二个选择?然后再次单击?是的,请帮助我们如何找到数字的索引?我们能用另一种方法写这个程序吗?通过查找所选值的索引和切片,push?这是什么意思?正如在
选项
数组中使用值并查找其索引一样?我的意思是,如果没有appendChild方法,可以使用push,slice?因此您想将
选项
推到select?是的,我想使用push,slice by the indexof()将选项推到第二个下拉列表中方法不按appendchild?如何找到数字的索引?我们能用另一种方法写这个程序吗?通过查找选定值的索引和切片,推送?
var firstSelect = document.getElementById("selectNumber");
var otherSelect = document.getElementById("status");

var option = ["1", "2", "3", "4", "5","6","7","8","9"];
for(i = 0; i < option.length; i++) 
{
    var opt = option[i];
    var el = document.createElement("option");
    el.textContent = opt;
    el.value = opt;
    select.appendChild(el);
}
function addOption(val){
    var option = document.createElement("option");
    option.text = val;
    return option;
}
firstSelect.onchange = function(){
    otherSelect.add(addOption(firstSelect.value));
    firstSelect.remove(firstSelect.selectedIndex);
};

otherSelect.onchange = function(){
    firstSelect.add(addOption(otherSelect.value));
    otherSelect.remove(otherSelect.selectedIndex);
}