我有一个来自 createElement 的 select 元素,我想用带有 onchange 事件的文本输入元素替换它,但是我的代码不起作用。这是代码(选择元素本身被附加到其他也创建的 div 元素):
var countess = 0;
function adadd(){
var child = document.getElementById("geneadd");
if (child.value === "add"){
countess++;
if (countess < 2) {
var divi=document.createElement("div");
divi.name = "diviena";
divi.id = "divienid";
divi.class = "table";
var elemdivi = document.getElementById("fieldsetid");
elemdivi.appendChild(divi);
}
var divii=document.createElement("div");
divii.name = "divienaa" + countess;
divii.id = "divienidd" + countess;
var elemdivii = document.getElementById("divienid");
elemdivii.appendChild(divii);
var sell=document.createElement("select");
sell.id = "den3erw" + countess;
sell.name = "oute3erw" + countess;
sell.onchange = "lechangefinal()";
var har = document.getElementById(divii.id);
har.appendChild(sell);
var opt=document.createElement("option");
opt.id = "disept" + countess/*<?php echo $varia; ?>*/;
opt.value = "";
var nar = document.getElementById(sell.id);
sell.appendChild(opt);
document.getElementById(opt.id).innerHTML="Select Gene...";
//...more options in between...
var opta=document.createElement("option");
opta.id = "other" + countess/*<?php echo $varia; ?>*/;
opta.value = "other";
var nari = document.getElementById(sell.id);
sell.appendChild(opta);
document.getElementById(opta.id).innerHTML="other...";
}
}
这是我想在创建元素上工作的功能:
function lechangefinal(){
for (var iii = 0; iii <= 100; iii++){
var childi = document.getElementById("den3erw" + iii);
if (childi.value === "other"){
parent.removeChild(childi);
var inpuat=document.createElement("input");
inpuat.type = "text";
inpuat.name = "2";
var elemi=document.getElementById("divienidd" + iii);
elemi.appendChild(inpuat);
}
}
}