gpt4 book ai didi

javascript - Internet Explorer Javascript/Dom 对象添加行问题

转载 作者:行者123 更新时间:2023-11-30 10:49:31 25 4
gpt4 key购买 nike

这是我的 Javascript 代码:

function generate(choice)
{
if(choice==1)
{

charge++;


var new_row=document.createElement("tr");
var name="row"+charge;
new_row.setAttribute("name",name);
new_row.setAttribute("id",name);

var col1=document.createElement("td");
var col2=document.createElement("td");
var col3=document.createElement("td");
var col4=document.createElement("td");

col1.setAttribute("width","205");
col2.setAttribute("width","191");
col3.setAttribute("width","182");
col4.setAttribute("width","127");

var list1=document.getElementById("rep0").cloneNode(true);
id="rep"+charge;

list1.setAttribute("id",id);

var list2=document.getElementById("item0").cloneNode(true);
name="items[]";
list2.setAttribute("name",name);
id="item"+charge;
list2.setAttribute("id",id);
list2.setAttribute("onChange","match_row(this.id);");


// clone_nodes(list2,"item0");

var text=document.createElement("input");
name="minutes[]";
text.setAttribute("name",name);
text.setAttribute("value","15");
id="minutes"+charge;
text.setAttribute("id",id);
text.setAttribute("type","text");

var text2=document.createElement("input");
name="charges[]";
text2.setAttribute("name",name);
text2.setAttribute("value","28.00");
id="charges"+charge;
text2.setAttribute("id",id);
text2.setAttribute("type","text");
//text2.setAttribute("onChange","charge_calculator();");

col1.appendChild(list1);
col2.appendChild(list2);
col3.appendChild(text);
col4.appendChild(text2);

new_row.appendChild(col1);
new_row.appendChild(col2);
new_row.appendChild(col3);
new_row.appendChild(col4);

charges1=document.getElementById("charges");
charges1.appendChild(new_row);

final_charge=charge;


}
else if(choice==2)
{

payment++;
var new_row2=document.createElement("tr");


var col11=document.createElement("td");
var col22=document.createElement("td");
var col33=document.createElement("td");

col11.setAttribute("width","205");
col22.setAttribute("width","206");
col33.setAttribute("width","297");


var list11=document.createElement("select");
name="payment_type[]";
list11.setAttribute("name",name);
id="payment_type"+payment;
list11.setAttribute("id",id);
list11.setAttribute("onChange","set_payment_type(this.id);");
clone_nodes(list11,"payment_type0");

var text1=document.createElement("input");
text1.setAttribute("type","text");
name="amount[]";
text1.setAttribute("name",name);
id="amount"+payment;
text1.setAttribute("id",id);


var list22=document.createElement("select");
name="account[]";
list22.setAttribute("name",name);
id="account"+payment;
list22.setAttribute("id",id);
list22.setAttribute("onChange","correspond2(this.id);");
clone_nodes(list22,"account0");


col11.appendChild(list11);
col22.appendChild(text1);
col33.appendChild(list22);

new_row2.appendChild(col11);
new_row2.appendChild(col22);
new_row2.appendChild(col33);


charges2=document.getElementById("payments");
charges2.appendChild(new_row2);
final_payment=payment;

}

}

这是我用来调用的 html 按钮代码

<input type="button" name="Add More" id="Add More" value="Add More" onClick="generate(1);" />

除 Internet Explorer 外,其他浏览器一切正常请帮助我,我被困住了。我也为 IE 锻炼过。

最佳答案

为了您自己的理智,请使用像 jQuery 这样的库实现这种事情。

关于javascript - Internet Explorer Javascript/Dom 对象添加行问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6322180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com