简体   繁体   English

Object.innerHTML未设置值

[英]Object.innerHTML not setting value

I am using object.innertHTML to set an HTML structure. 我正在使用object.innertHTML设置HTML结构。 But its not setting initial TR and TD elements.. Below is the code 但是它没有设置初始的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;

But output getting is 但是输出得到的是

"<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>"

intial TR and TD element are mising. 最初的TR和TD元素是错误的。 What could be the reason 可能是什么原因

If you want to insert a large chunk of HTML like you're doing, and don't want to replace the entire .innerHTML of the parent object (your table), use .insertAdjacentHTML() . 如果您想像这样做一样插入大量HTML,并且不想替换父对象(您的表)的整个.innerHTML ,请使用.insertAdjacentHTML()

Demo: 演示: jsFiddle

Script: 脚本:

var containerObject = document.getElementById("table1"); 
containerObject.insertAdjacentHTML( 'beforeEnd', "<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>")

HTML: HTML:

<table id="table1">
</table>

I get an error in the javascript console when trying to create a "blank" DOM element. 尝试创建“空白” DOM元素时,javascript控制台出现错误。 You can't do document.createElement("") . 您不能执行document.createElement("") It looks like you're trying to create a table so, try this: 看起来您正在尝试创建表,因此,请尝试以下操作:

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

http://jsfiddle.net/fCBne/ http://jsfiddle.net/fCBne/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM