Javascript Object.innerHTML未设置值

Javascript Object.innerHTML未设置值,javascript,Javascript,我正在使用object.innertHTML设置HTML结构。但它没有设置初始TR和TD元素。。下面是代码 var previousInnerHTML = new String(); previousInnerHTML = previousInnerHTML.concat("<TR class='evenrow ' __eventAdded='true' isSubTotalRow='false' usable='false' index='40'><TD><I

我正在使用object.innertHTML设置HTML结构。但它没有设置初始TR和TD元素。。下面是代码

 var previousInnerHTML = new String();
 previousInnerHTML = previousInnerHTML.concat("<TR class='evenrow ' __eventAdded='true' isSubTotalRow='false' usable='false' index='40'><TD><INPUT id=check_table1 onclick=WebForm.markRowForSelection(event) type=checkbox xformstype='checkbox' doEBIValidate='false' __cID='c514' transactional='true' model='null' freemodel='false' databound='true' freeform='false' _initialized='true' originalTitle dataBoundElement='true' selectnotifier='true' trueValue='null' falseValue='null'></INPUT></TD><TD><DIV id=xfe2 class=fieldsbox><INPUT id=output2 class=input title='Provide value for Output2' type=text xformstype='input' doEBIValidate='false' __parent='table1' __cID='c515' transactional='true' model='null' freemodel='false' databound='true' freeform='false' _initialized='true' originalTitle='Provide value for Output2' xql='.//ID' ref='.//ID' _inTable='true' dataBoundElement='true'></DIV></TD><TD><DIV id=xfe4 class=fieldsbox><INPUT id=output4 class='input output' title='Value for Output4' readOnly xformstype='output' doEBIValidate='false' __parent='table1' __cID='c516' transactional='true' model='null' freemodel='false' databound='true' freeform='false' _initialized='true' originalTitle='Value for Output4' xql='EMPID' isOutputControl='true' ref='EMPID' _inTable='true' dataBoundElement='true'></DIV></TD><TD><DIV id=xfe6 class=fieldsbox><INPUT id=output5 class='input output' title='Value for Output5' readOnly xformstype='output' doEBIValidate='false' __parent='table1' __cID='c517' transactional='true' model='null' freemodel='false' databound='true' freeform='false' _initialized='true' originalTitle='Value for Output5' xql='ROLEID' isOutputControl='true' ref='ROLEID' _inTable='true' dataBoundElement='true'></DIV></TD><TD><DIV id=xfe8 class=fieldsbox><INPUT id=output3 class='input output' title='Value for Output3' readOnly xformstype='output' doEBIValidate='false' __parent='table1' __cID='c518' transactional='true' model='null' freemodel='false' databound='true' freeform='false' _initialized='true' originalTitle='Value for Output3' xql='num1' isOutputControl='true' ref='num1' _inTable='true' dataBoundElement='true'></DIV></TD><TD><DIV id=xfe10 class=fieldsbox><INPUT id=output1 class='input output' title='Value for Output1' readOnly xformstype='output' doEBIValidate='false' __parent='table1' __cID='c519' transactional='true' model='null' freemodel='false' databound='true' freeform='false' _initialized='true' originalTitle='Value for Output1' xql='num2' isOutputControl='true' ref='num2' _inTable='true' dataBoundElement='true'></DIV></TD></TR>");

 var buttonObject = document.createElement("");
 buttonObject.innerHTML = previousInnerHTML;
var previousInnerHTML=新字符串();
previousInnerHTML=previousInnerHTML.concat(“”);
var buttonObject=document.createElement(“”);
buttonObject.innerHTML=previousInnerHTML;
但产出的增加是不可能的

"<INPUT id=check_table1 onclick=WebForm.markRowForSelection(event) type=checkbox xformstype="checkbox" doEBIValidate="false" __cID="c514" transactional="true" model="null" freemodel="false" databound="true" freeform="false" _initialized="true" originalTitle dataBoundElement="true" selectnotifier="true" trueValue="null" falseValue="null"></INPUT></TD><TD>
<DIV id=xfe2 class=fieldsbox><INPUT id=output2 class=input title="Provide value for Output2" type=text xformstype="input" doEBIValidate="false" __parent="table1" __cID="c515" transactional="true" model="null" freemodel="false" databound="true" freeform="false" _initialized="true" originalTitle="Provide value for Output2" xql=".//ID" ref=".//ID" _inTable="true" dataBoundElement="true"></DIV></TD><TD>
<DIV id=xfe4 class=fieldsbox><INPUT id=output4 class="input output" title="Value for Output4" readOnly xformstype="output" doEBIValidate="false" __parent="table1" __cID="c516" transactional="true" model="null" freemodel="false" databound="true" freeform="false" _initialized="true" originalTitle="Value for Output4" xql="EMPID" isOutputControl="true" ref="EMPID" _inTable="true" dataBoundElement="true"></DIV></TD><TD>
<DIV id=xfe6 class=fieldsbox><INPUT id=output5 class="input output" title="Value for Output5" readOnly xformstype="output" doEBIValidate="false" __parent="table1" __cID="c517" transactional="true" model="null" freemodel="false" databound="true" freeform="false" _initialized="true" originalTitle="Value for Output5" xql="ROLEID" isOutputControl="true" ref="ROLEID" _inTable="true" dataBoundElement="true"></DIV></TD><TD>
<DIV id=xfe8 class=fieldsbox><INPUT id=output3 class="input output" title="Value for Output3" readOnly xformstype="output" doEBIValidate="false" __parent="table1" __cID="c518" transactional="true" model="null" freemodel="false" databound="true" freeform="false" _initialized="true" originalTitle="Value for Output3" xql="num1" isOutputControl="true" ref="num1" _inTable="true" dataBoundElement="true"></DIV></TD><TD>
<DIV id=xfe10 class=fieldsbox><INPUT id=output1 class="input output" title="Value for Output1" readOnly xformstype="output" doEBIValidate="false" __parent="table1" __cID="c519" transactional="true" model="null" freemodel="false" databound="true" freeform="false" _initialized="true" originalTitle="Value for Output1" xql="num2" isOutputControl="true" ref="num2" _inTable="true" dataBoundElement="true"></DIV></TD></TR>"
”
"

初始TR和TD元素错误。当我试图创建“空白”DOM元素时,javascript控制台中出现错误的原因是什么。您不能执行
document.createElement(“”)
。看起来您正在尝试创建一个表,请尝试以下操作:

 var buttonObject = document.createElement("table");

在尝试创建“空白”DOM元素时,javascript控制台中出现错误。您不能执行
document.createElement(“”)
。看起来您正在尝试创建一个表,请尝试以下操作:

 var buttonObject = document.createElement("table");

如果您想像现在这样插入大量HTML,并且不想替换父对象(表)的整个
.innerHTML
,请使用
.insertAdjacentHTML()

演示:

脚本:
var containerObject=document.getElementById(“表1”);
containerObject.insertAdjacentHTML('beforeEnd',“”)
HTML:
如果您想像现在这样插入大量HTML,并且不想替换父对象(表)的整个
.innerHTML
,请使用
.insertAdjacentHTML()

演示:

脚本:
var containerObject=document.getElementById(“表1”);
containerObject.insertAdjacentHTML('beforeEnd',“”)
HTML:


为什么要使用
新字符串()
而不是
”?尝试使用“”,用力工作。。试过另一种方法..仅此而已..还有,为什么要用
x=x.concat(y)
代替
x=x+y
甚至
x+=y
?所有工作。您是否正在尝试在按钮元素中插入tr td元素?我认为
document.createElement(“”
不起作用。为什么
new String()
而不是
”?尝试了“”,但效果很好。。试过另一种方法..仅此而已..还有,为什么要用
x=x.concat(y)
代替
x=x+y
甚至
x+=y
?所有工作。您是否试图在按钮元素中插入trtd元素?我认为
document.createElement(“”)不起作用。我建议使用“tbody”而不是“table”。否则Chrome会在表内容周围插入一个
tbody
节点。嗨..我已经有了一个表结构。我想做的是把这个TR块包括进去。希望您能找到me.var containerObject=document.getElementById(“表1”);containerObject.childNodes.item(1).appendChild(buttonObject)@SanjaiPalliyil也许你想看看
documentFragment
s。他们的行为和我想的一模一样。我建议用“tbody”代替“table”。否则Chrome会在表内容周围插入一个
tbody
节点。嗨..我已经有了一个表结构。我想做的是把这个TR块包括进去。希望您能找到me.var containerObject=document.getElementById(“表1”);containerObject.childNodes.item(1).appendChild(buttonObject)@SanjaiPalliyil也许你想看看
documentFragment
s。它们的行为完全符合我的想法。这比
containerObject.innerHTML+=string
好吗?@JanDvorak是的,它更有效,尤其是在必须使用
.innerHTML+=
完全重建的大块现有HTML上。此外,它还有其他您无法使用的选项。innerHTML
开始之前
结束之后
。这比
containerObject.innerHTML+=string
好吗?@JanDvorak是的,它更有效,尤其是在必须使用
完全重建的大块现有HTML上。innerHTML+=
。此外,它还有其他您无法使用的选项。
。innerHTML
开始前
结束后