Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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 添加元素在html中添加两个位置_Javascript_Html - Fatal编程技术网

Javascript 添加元素在html中添加两个位置

Javascript 添加元素在html中添加两个位置,javascript,html,Javascript,Html,document.querySelector'submit'。onclick==>{ document.querySelectorAll.merge.forEachselect=>{ const option=document.createElement'option'; option.innerHTML=document.querySelector'text-get'。值; document.querySelector.merge.appendoption; } 返回false; }; 你很接

document.querySelector'submit'。onclick==>{ document.querySelectorAll.merge.forEachselect=>{ const option=document.createElement'option'; option.innerHTML=document.querySelector'text-get'。值; document.querySelector.merge.appendoption; } 返回false; };
你很接近。试着这样做:

const selects=document.querySelectorAll.merge',//缓存元素,这样就不会经常查询DOM 输入=document.querySelector'text-get'; document.querySelector'submit'。onclick==>{ selects.forEachselect=>{ 让option=document.createElement'option'; option.innerHTML=input.value; 选择.appendoption }; 返回false; }; 使用select.appendoption而不是document.querySelector.merge.appendoption