表格行点击添加但未显示在源代码中(Javascript) [英] Table Row adding on click but not showing in source code(Javascript)
本文介绍了表格行点击添加但未显示在源代码中(Javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
函数 addRow(tableID){
var table = document .getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell( 0 );
cell1.setAttribute(' align',' 居中);
var category_ddl = 文档 .createElement(" 选择");
category_ddl.setAttribute(' id',' item_lst');
// category_ddl.setAttribute('onchange','per_unit()');
var select_default_val = 文档 .createElement(" 选项");
select_default_val.text = ' ------- Select ------';
select_default_val.selected = true ;
category_ddl.appendChild(select_default_val);
/* ************************ ****************************************************** ******************************************/
var category_first = 文档 .createElement(" optgroup");
category_first.label = ' 第一类';
var optionval = 文档 .createElement(" 选项");
optionval.text = " ;
optionval.value = ' 4';
var optionval_1 = 文档 .createElement(" 选项");
optionval_1.text = " ;
optionval_1.value = ' 4';
var optionval_2 = 文档 .createElement(" 选项");
optionval_2.text = " ;
optionval_2.value = ' 4';
var optionval_3 = 文档 .createElement(" 选项");
optionval_3.text = " ;
optionval_3.value = ' 4';
// category_first.appendChild(document.createElement("Cereal"));
category_first.appendChild(optionval);
category_first.appendChild(optionval_1);
category_first.appendChild(optionval_2);
category_first.appendChild(optionval_3);
category_ddl.appendChild(category_first);
var anchor _ = 文档 .createElement(" 一个");
// anchor_.id ='add_sign'+(counter + 1);
anchor_.appendChild(文档 .createTextNode(" ));
anchor_.setAttribute(' 名称',' 锚定);
anchor_.id = ' add_row';
anchor_.setAttribute(" ," addRow('order_table')");
cell1.appendChild(anchor_);
/* ************************ ****************************************************** ******************************************/
var category_second = 文档 .createElement(" optgroup");
category_second.label = ' 第二类';
var option_2_cat = 文档 .createElement(" 选项");
option_2_cat.text = " ;
option_2_cat.value = ' 34';
var option_2_cat_2 = 文档 .createElement(" 选项");
option_2_cat_2.text = " ;
option_2_cat_2.value = ' 34';
var option_2_cat_3 = 文档 .createElement(" 选项");
option_2_cat_3.text = " ;
option_2_cat_3.value = ' 34';
var option_2_cat_4 = 文档 .createElement(" 选项");
option_2_cat_4.text = " ;
option_2_cat_4.value = ' 34';
category_second.appendChild(option_2_cat);
category_second.appendChild(option_2_cat_2);
category_second.appendChild(option_2_cat_3);
category_second.appendChild(option_2_cat_4);
category_ddl.appendChild(category_second);
cell1.appendChild(category_ddl);
/* ************************ ****************************************************** ******************************************/
// var category_second = document.createElement("optgroup");
// category_second.label ='第二类别';
var cell2 = row.insertCell( 1 );
cell2.setAttribute(' align',' 居中);
cell2.innerHTML = ' 00.00'
/* ************************ ****************************************************** ******************************************/
// var category_third = document.createElement("optgroup");
// category_third.label ='第三类';
var cell3 = row.insertCell( 2 );
cell3.setAttribute(' align',' 居中);
var qty_txt = 文档 .createElement(' 输入');
qty_txt.type = ' 文本';
qty_txt.id = ' qty';
qty_txt.size = ' 10';
qty_txt.value = ' 00';
qty_txt.style.textAlign = ' center';
qty_txt.name = ' qty';
qty_txt.text = ' 00';
cell3.appendChild(qty_txt);
// var element2 = document.createElement("input");
// element2.type ="text";
// cell3.appendChild(element2);
/* ************************ ****************************************************** ******************************************/
var cell4 = row.insertCell( 3 );
cell4.setAttribute(' align',' 居中);
cell4.innerHTML = ' 00';
/* ************************ ****************************************************** ******************************************/
计数器++;
}
解决方案
以下是必需的代码-
// 调试代码:: var _debugEnabled = false ; 函数 enableDebug(flag) { _debugEnabled =标志; 如果(_ debugEnabled) 文档 .write(' < div id ="debugCoder ><输入类型="文本"size =" 100"id =" debugText><输入类型="按钮"value =" Eval"onclick =" debug()><输入类型= "button" value =查看源代码" onclick ="viewSource()"></div>'); 其他 如果(文档 .getElementById(' debugCoder')!= 空) 文档 .body.removeChild(_D.getElementById(' debugCoder ')); } 函数 debug() { var debugTextObj = 文档 .getElementById(' debugText'); 如果(debugTextObj) 警报(评估(debugTextObj.value)) } 函数 viewSource() { var win = 窗口 .open(' ',' _ blank'); var 结果= 文档 .documentElement.innerHTML; var match = " ; var re = 新 RegExp (" ," g"); var newresults = results.replace(re," ); win.文档 .write(' < pre>' + newresults + ' </pre>'); } // 取消注释此代码以调试javascript代码 // enableDebug(true);
希望这对您有所帮助.
问候,
尼拉·索尼(Nial Soni)
hi
i am add row in table on click event and it is adding successfully but when i am going to see source code , it is not showing me source code what ever i have added runtime can any one help me how can i do this..?
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
cell1.setAttribute('align','center');
var category_ddl = document.createElement("select");
category_ddl.setAttribute('id','item_lst');
//category_ddl.setAttribute('onchange','per_unit()');
var select_default_val=document.createElement("option");
select_default_val.text='-------Select------';
select_default_val.selected=true;
category_ddl.appendChild(select_default_val);
/*****************************************************************************************************************/
var category_first=document.createElement("optgroup");
category_first.label='First Category';
var optionval=document.createElement("option");
optionval.text="Item One";
optionval.value='4';
var optionval_1=document.createElement("option");
optionval_1.text="Item One";
optionval_1.value='4';
var optionval_2=document.createElement("option");
optionval_2.text="Item One";
optionval_2.value='4';
var optionval_3=document.createElement("option");
optionval_3.text="Item One";
optionval_3.value='4';
//category_first.appendChild(document.createElement("Cereal"));
category_first.appendChild(optionval);
category_first.appendChild(optionval_1);
category_first.appendChild(optionval_2);
category_first.appendChild(optionval_3);
category_ddl.appendChild(category_first);
var anchor_=document.createElement("a");
//anchor_.id='add_sign'+(counter+1);
anchor_.appendChild(document.createTextNode("+ "));
anchor_.setAttribute('name','anchor');
anchor_.id='add_row';
anchor_.setAttribute("onclick","addRow('order_table')");
cell1.appendChild(anchor_);
/*****************************************************************************************************************/
var category_second=document.createElement("optgroup");
category_second.label='Second Category';
var option_2_cat=document.createElement("option");
option_2_cat.text="Second Item";
option_2_cat.value='34';
var option_2_cat_2=document.createElement("option");
option_2_cat_2.text="Second Item";
option_2_cat_2.value='34';
var option_2_cat_3=document.createElement("option");
option_2_cat_3.text="Second Item";
option_2_cat_3.value='34';
var option_2_cat_4=document.createElement("option");
option_2_cat_4.text="Second Item";
option_2_cat_4.value='34';
category_second.appendChild(option_2_cat);
category_second.appendChild(option_2_cat_2);
category_second.appendChild(option_2_cat_3);
category_second.appendChild(option_2_cat_4);
category_ddl.appendChild(category_second);
cell1.appendChild(category_ddl);
/*****************************************************************************************************************/
//var category_second=document.createElement("optgroup");
//category_second.label='Second Category';
var cell2 = row.insertCell(1);
cell2.setAttribute('align','center');
cell2.innerHTML = '00.00'
/*****************************************************************************************************************/
//var category_third=document.createElement("optgroup");
//category_third.label='Third Category';
var cell3 = row.insertCell(2);
cell3.setAttribute('align','center');
var qty_txt=document.createElement('input');
qty_txt.type='text';
qty_txt.id='qty';
qty_txt.size='10';
qty_txt.value='00';
qty_txt.style.textAlign='center';
qty_txt.name='qty';
qty_txt.text='00';
cell3.appendChild(qty_txt);
//var element2 = document.createElement("input");
//element2.type = "text";
//cell3.appendChild(element2);
/*****************************************************************************************************************/
var cell4 = row.insertCell(3);
cell4.setAttribute('align','center');
cell4.innerHTML='00';
/*****************************************************************************************************************/
counter++;
}
解决方案
Here is the required code -
// Debugging Code :: var _debugEnabled = false; function enableDebug(flag) { _debugEnabled = flag; if(_debugEnabled) document.write('<div id="debugCoder"><input type="text" size="100" id="debugText"><input type="button" value="Eval" onclick="debug()"> <input type="button" value="View Source" onclick="viewSource()"></div>'); else if(document.getElementById('debugCoder') != null) document.body.removeChild(_D.getElementById('debugCoder')); } function debug() { var debugTextObj = document.getElementById('debugText'); if(debugTextObj) alert(eval(debugTextObj.value)) } function viewSource() { var win = window.open('','_blank'); var results = document.documentElement.innerHTML; var match = "<"; var re = new RegExp("<", "g"); var newresults = results.replace(re, "<"); win.document.write('<pre>' +newresults+'</pre>' ); } // Uncomment this code to debug the javascript code //enableDebug(true);
Hope this helps you out..
Regards,
Niral Soni
这篇关于表格行点击添加但未显示在源代码中(Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文