本文介绍了由createElement和appendChild在表中计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好, i有一个表,可以使用 createElement,appendChild,removeChild动态创建和删除行。 when我已经添加了所需的行数并输入了我的数据,我想b $ b想计算每一行的总数。 当我尝试的时候,我收到错误: "错误:''元素[...]''为空或不是对象 i有尝试循环遍历表单中的所有元素,这给了 我的名字&每个元素的价值。 当我按名称调用元素时,我收到上述错误。 通过剪切和粘贴更容易解释我的html来源 文件如下: 我非常感谢任何指针,这里是代码。 < script language =" JavaScript"类型= QUOT;文本/ JavaScript的" > <! - var InternetExplorer = navigator.appName.indexOf(" Microsoft")!= -1; var globalChanged = false; var globalNewRowChanged = false; var globalClaimLnsRowNum = 1; 函数ex_amount( s_cur){ 开关(s_cur) { 案例''1'': 返回'' 1.2''; 休息; 案例''2'': 返回''0.6''; 休息; 案例''3'': 返回''1.5''; 休息; case''4'': 返回''2''; 休息; case''5'': 返回''1'; 休息; 默认值: 返回0; } } 函数detail_row(s_goods_id,s_unit_price,s_currency_id,s _quantity,s_uplift,s_total_line,s_incl_uplift,s_in cl_uplift_euro) { var body = document。 body; var Table,theRow,aCell,aTextBox,tablebody2,rowSec2; var theTable; var rowSec1,currenttext; var opt1,sel2; var cellSec1,cellSec2,cellSec3,cellSec4,cellSec5; var cellSec6,cellSec7,cellSec8,cellSec9,cellSec10; theTable = document.getElementById(''formation'')。getE lementsByTagName(''tbody'')[0]; tablebody2 = document.createElement('''TBODY' '); rowSec2 = document.createElement(''TR''); cellSec2 = document.createElement(''TD''); sel2 = document.createElement(''select''); sel2.name =''2d_cmb_goods__''+ globalClaimLnsRowNum; opt1 = document.createElement( ''选项''); opt1.value =''9''; if(opt1.value == s_goods_id){opt1.setAttribute(''select ed'', true);} opt1.innerHTML =''Airconditioners''; sel2.appendChild(opt1); opt1 = document.createElement(''option''); opt1.value ='''5''; if(opt1.value == s_goods_id){opt1.setAttribute(''select ed'', true);} opt1.innerHTML =''Audio Goods''; sel2.appendChild(opt1); opt1 = document.createElement(''option''); opt1.value ='''13'' ; if(opt1.value == s_goods_id){opt1.setAttribute(''select ed'', true);} opt1.innerHTML =''Video Recorder''; sel2.appendChild(opt1); cellSec2.appendChild(sel2); rowSec2 .appendChild(cellSec2); cellSec3 = document.createElement(''TD''); aTextBox = document.createElement(''input'' ); aTextBox.type =''text''; aTextBox.value = nz(s_unit_price); aTextBox.size =' '10'; aTextBox.name =''2d_txt_unit_price__''+ globalClaimLnsRowNum; cellSec3.appendChild(aTextBox); rowSec2.appendChild(cellSec3); cellSec4 = document.createElement('''TD'') ; sel2 = document.createElement(''select''); sel2.name =''2d_cmb_currency__''+ globalClaimLnsRowNum; opt1 = document.createElement(''option''); opt1.value =''1'; if(opt1.value == s_currency_id){opt1 .setAttribute(''选择'', true);} opt1.innerHTML =''US $''; sel2 .appendChild(opt1); opt1 = document.createElement(''option''); opt1.value ='''''; if(opt1.value == s_currency_id){opt1.setAttribute(''选择'', true);} opt1.innerHTML ='' STG''; sel2.appendChild(opt1); opt1 = document.createElement(''option''); opt1 .value =''3''; if(opt1.value == s_currency_id){opt1.setAttribute( '选择'', true);} opt1.innerHTML =''A $''; sel2.appendChild(opt1 ); opt1 = document.createElement(''option''); opt1.value =''4''; if (opt1.value == s_currency_id){opt1.setAttribute(''选择'', true);} opt1.innerHTML =''NZ $'' ; sel2.appendChild(opt1); opt1 = document.createElement(''option''); opt1.value =' '5''; if(opt1.value == s_currency_id){opt1.setAttribute(''选择'', true);} opt1.innerHTML =''BHAT''; sel2.appendChild(opt1); cellSec4.appendChild(sel2); rowSec2.appendChild(cellSec4); cellSec5 = document.createElement(''TD''); aTextBox = document.createElement(''输入''); aTextBox.type =''text''; aTextBox.value = nz(s_quantity); aTextBox。大小='''5''; aTextBox.name =''2d_txt_quantity__''+ globalClaimLnsRowNum; cellSec5.appendChild(aTextBox); rowSec2.appendChild(cellSec5); cellSec6 = document.createElement(''TD''); aTextBox = document.createElement(''input' '); aTextBox.type =''text''; aTextBox.value = nz(s_total_line); aTextBox.size = ''5'; aTextBox.name =''2d_txt_total_line__''+ globalClaimLnsRowNum; cellSec6.appendChild(aTextBox); rowSec2 .appendChild(cellSec6); cellSec7 = document.createElement(''TD''); sel2 = document.createElement(''select'' ); sel2.name =''2d_cmb_uplift__''+ globalClaimLnsRowNum; opt1 = document.createElement(''option''); opt1.value =''100''; if(opt1.value == s_uplift){opt1.setAttribute(''selected'',true);} opt1.innerHTML =''100%''; sel2.appendChild(opt1); opt1 = document.createElement(''选项''); opt1.value ='''105''; if(opt1.value == s_uplift){opt1.setAttribute(''selected'', true);} opt1.innerHTML =''105%''; sel2.appendChild(opt1); opt1 = document。 createElement(''option''); opt1.value =''110''; if(opt1.value == s_uplift){opt1.setAttribute(' 'selected'',true);} opt1.innerHTML =''110%''; sel2.appendChild(opt1); opt1 = document.createElement(''option''); opt1.value =''0''; if(opt1.value == s_uplift){ opt1.setAttribute(''selected'',true);} opt1.innerHTML =''other''; sel2.appendChild(opt1); cellSec7.appendChild(sel2); rowSec2.appendChild(cellSec7); cellSec8 = document.createElem ent(''TD''); aTextBox = document.createElement(''input''); aTextBox.type =''text''; aTextBox.value = nz(s_incl_uplift); aTextBox.size ='''3'; aTextBox.name =''2d_txt_incl_uplift__'' + globalClaimLnsRowNum; cellSec8.appendChild(aTextBox); rowSec2.appendChild(cellSec8); cellSec9 = document.createElement (''TD''); aTextBox = document.createElement(''input''); aTextBox.type =''text''; aTextBox.value = nz(s_incl_uplift_euro); aTextBox.name ='''2d_txt_incl_uplift_euro__''+ globalClaimLnsRowNum; aTextBox.size ='''5''; aTextBox.onchange = function(){calculateTab(globalCl aimLnsRowNum);} cellSec9.appendChild(aTextBox); rowSec2.appendChild(cellSec9); cellSec10 = document.createElement(''TD''); B uttonSupprimer = document.createElement(''input''); ButtonSupprimer.type =''button''; ButtonSupprimer.value =''remove''; ButtonSupprimer.onclick = function(){formation.remov eChild(tablebody2)} cellSec10.appendChild(ButtonSupprimer); rowSec2.appendChild( cellSec10); tablebody2.appendChild(rowSec2); formation.appendChild(tablebody2); globalClaimLnsRowNum = globalClaimLnsRowNum + 1 ; } 函数calculateTab(n_line_no){ var oForm = document.forms [0]; alert(''line number =''+ n_line_no); oForm.elements [''2d_txt_total_line__''+ n_line_no]。 value = nz(oForm.elements [''2d_txt_unit_price__''+ n_line_no] .value)* nz(oForm.elements [''2d_txt_quantity__''+ n_line_no] .value); } 函数nz(s_val){ var s_dat atype =" undefined"; if(s_val == null || s_val ==''''|| isNaN(s_val)|| typeof(s_val)== s_datatype){ //返回isNaN(num)?0:num; 返回0; } else { // alert(s_val); 返回parseFloat(s_val ); } } 函数resetForm(){ var oForm = document。 form [0]; for(i = 0; i< oForm.elements.length; i ++){ oForm.elements [i] .value ="" ;; } } 函数setLabel(s_message,s_label_name){ 文件。 all(s_label_name).innerText = s_message; } // - > < / script> < html> < head> < / head> < body> < form method =" post"行动= QUOT;" ID = QUOT; form1的" name =" form1"> < table> < tr> < td width ='''4%' '> < tr> < td colspan ='''6''> < / td> < / tr> < tr> < td>& nbsp;< / td> ; < td>< input type =" button"名称= QUOT;将Button2" value =" change label" onclick = setlabel(''这里有一些不同的文字'',''label_detail'');> < / td> ; < td>< input type =" button"名称= QUOT;按钮和QUOT; value =" calculate" onclick = calculateTab(''1'');>< / td> < td colspan =''1'' align =''right''>& nbsp;< / td> < td> < input name =''cmd_detail_new''type = ''button''id =''cmd_detail_new'' value =''添加行[点击此处]''onclick = detail_row();> < / td> < td>& nbsp;< / td> < td colspan =''3''align =''right''> ;总计< / td> < td> <输入名称=''2d_txt_detail_total''type =''text'' id =''2d_txt_detail_total''value =''''size =''10'' onChange = document.forms [0] .elements [''txt_haschanged'']。value = ''是';;> < / td> < td width =''16%''> = EUR< / td> < td width =''30%''> < input name =''2d_txt_detail_to tal_euro''type =''text'' id =''2d_txt_detail_total_euro''value =''''size =''10'' onChange = document。 forms [0] .elements [''txt_haschanged'']。value =''yes'';>< / td> < / td> < / tr> < tr> < td colspan ='''6''>< / td> < / tr> < / table> < / td> < / tr> < / table> < table> < tr> < td height ='''20''valign =''top''> < table width =''100%''border =''1''cellpadding =''0''cellspacing =''0'' valign =''top''id =''形成''> < tr> < td width =''15%''>& nbsp;< b> GOODS< / b>< / td> < td width ='''5%'' >& nbsp;< b> UNIT PRICE< / b>< / td> < td width =''10%''>& nbsp;< b> CURRENCY< / b>< / td> < td width ='' 5%''>& nbsp;< b> QUANTITY< / b>< / td> < td width =''5%''>& nbsp;< ; b> TOTAL LINE< / b>< / td> < td width =''5%''>& nbsp;< b> UPLIFT(%)< / b>< / td> < td width =''5%''>& nbsp;< b> INCL。 UPLIFT< / b>< / td> < td width =''5%''>& nbsp;< b> = EUR< / b>< / td> < td width =''5%''>& nbsp;< b>& nbsp;< / b>< / td> < / tr> < tr> < td colspan =''10''> < label id =''label_detail''>没有记录找到< / label> < / td> < / tr> < ; input type =''text''id =''2d_txt_detail_ids'' name =''2d_txt_detail_ids''value =''''> < input type =''text''id =''txt_update_ids''name =''txt_update_ids'' value =''''> < / table> < / td> < / tr> < / table> < / form> < / body> < / html> 感谢您的帮助,kie ps解决了以下问题的功能setLabel:< label id =''label_detail''> 由于我不知道的原因而失败,对此的任何指针都将是 赞。hello,i have a table that creates and deletes rows dynamically usingcreateElement, appendChild, removeChild.when i have added the required amount of rows and input my data, iwould like to calculate the totals in each row.when i try however, i receive the error:"Error: ''elements[...]'' is null or not an object"i have tried looping through all elements in the form and this givesme the name & value of each element.when i call the element by name however, i receive the above error.it is easier to explain by cuting and pasting the source of my htmlfile below:i''d greatly appreciate any pointers, here''s the code.<script language="JavaScript" type="text/JavaScript" ><!--var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;var globalChanged = false;var globalNewRowChanged = false;var globalClaimLnsRowNum = 1;function ex_amount(s_cur){switch (s_cur){case ''1'':return ''1.2'';break;case ''2'':return ''0.6'';break;case ''3'':return ''1.5'';break;case ''4'':return ''2'';break;case ''5'':return ''1'';break;default:return 0;}}function detail_row(s_goods_id,s_unit_price,s_currency_id,s _quantity,s_uplift,s_total_line,s_incl_uplift,s_in cl_uplift_euro){var body=document.body;var Table,theRow,aCell,aTextBox,tablebody2,rowSec2;var theTable;var rowSec1,currenttext;var opt1,sel2;var cellSec1,cellSec2,cellSec3,cellSec4,cellSec5;var cellSec6,cellSec7,cellSec8,cellSec9,cellSec10;theTable=document.getElementById(''formation'').getE lementsByTagName(''tbody'')[0];tablebody2 = document.createElement(''TBODY'');rowSec2=document.createElement(''TR'');cellSec2=document.createElement(''TD'');sel2=document.createElement(''select'');sel2.name=''2d_cmb_goods__'' + globalClaimLnsRowNum;opt1=document.createElement(''option'');opt1.value=''9'';if (opt1.value==s_goods_id){opt1.setAttribute(''select ed'',true);}opt1.innerHTML=''Airconditioners'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''5'';if (opt1.value==s_goods_id){opt1.setAttribute(''select ed'',true);}opt1.innerHTML=''Audio Goods'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''13'';if (opt1.value==s_goods_id){opt1.setAttribute(''select ed'',true);}opt1.innerHTML=''Video Recorder'';sel2.appendChild(opt1);cellSec2.appendChild(sel2);rowSec2.appendChild(cellSec2);cellSec3=document.createElement(''TD'');aTextBox=document.createElement(''input'');aTextBox.type = ''text'';aTextBox.value = nz(s_unit_price);aTextBox.size = ''10'';aTextBox.name = ''2d_txt_unit_price__'' + globalClaimLnsRowNum;cellSec3.appendChild(aTextBox);rowSec2.appendChild(cellSec3);cellSec4=document.createElement(''TD'');sel2=document.createElement(''select'');sel2.name=''2d_cmb_currency__'' + globalClaimLnsRowNum;opt1=document.createElement(''option'');opt1.value=''1'';if (opt1.value==s_currency_id){opt1.setAttribute(''sel ected'',true);}opt1.innerHTML=''US$'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''2'';if (opt1.value==s_currency_id){opt1.setAttribute(''sel ected'',true);}opt1.innerHTML=''」STG'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''3'';if (opt1.value==s_currency_id){opt1.setAttribute(''sel ected'',true);}opt1.innerHTML=''A$'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''4'';if (opt1.value==s_currency_id){opt1.setAttribute(''sel ected'',true);}opt1.innerHTML=''NZ$'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''5'';if (opt1.value==s_currency_id){opt1.setAttribute(''sel ected'',true);}opt1.innerHTML=''BHAT'';sel2.appendChild(opt1);cellSec4.appendChild(sel2);rowSec2.appendChild(cellSec4);cellSec5=document.createElement(''TD'');aTextBox=document.createElement(''input'');aTextBox.type = ''text'';aTextBox.value = nz(s_quantity);aTextBox.size = ''5'';aTextBox.name = ''2d_txt_quantity__'' + globalClaimLnsRowNum;cellSec5.appendChild(aTextBox);rowSec2.appendChild(cellSec5);cellSec6=document.createElement(''TD'');aTextBox=document.createElement(''input'');aTextBox.type = ''text'';aTextBox.value = nz(s_total_line);aTextBox.size = ''5'';aTextBox.name = ''2d_txt_total_line__'' + globalClaimLnsRowNum;cellSec6.appendChild(aTextBox);rowSec2.appendChild(cellSec6);cellSec7=document.createElement(''TD'');sel2=document.createElement(''select'');sel2.name=''2d_cmb_uplift__'' + globalClaimLnsRowNum;opt1=document.createElement(''option'');opt1.value=''100'';if (opt1.value==s_uplift){opt1.setAttribute(''selected '', true);}opt1.innerHTML=''100%'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''105'';if (opt1.value==s_uplift){opt1.setAttribute(''selected '', true);}opt1.innerHTML=''105%'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''110'';if (opt1.value==s_uplift){opt1.setAttribute(''selected '', true);}opt1.innerHTML=''110%'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''0'';if (opt1.value==s_uplift){opt1.setAttribute(''selected '', true);}opt1.innerHTML=''other'';sel2.appendChild(opt1);cellSec7.appendChild(sel2);rowSec2.appendChild(cellSec7);cellSec8=document.createElement(''TD'');aTextBox=document.createElement(''input'');aTextBox.type = ''text'';aTextBox.value = nz(s_incl_uplift);aTextBox.size = ''3'';aTextBox.name = ''2d_txt_incl_uplift__'' + globalClaimLnsRowNum;cellSec8.appendChild(aTextBox);rowSec2.appendChild(cellSec8);cellSec9=document.createElement(''TD'');aTextBox=document.createElement(''input'');aTextBox.type = ''text'';aTextBox.value = nz(s_incl_uplift_euro);aTextBox.name = ''2d_txt_incl_uplift_euro__'' +globalClaimLnsRowNum;aTextBox.size = ''5'';aTextBox.onchange=function(){calculateTab(globalCl aimLnsRowNum);}cellSec9.appendChild(aTextBox);rowSec2.appendChild(cellSec9);cellSec10=document.createElement(''TD'');ButtonSupprimer=document.createElement(''input'');ButtonSupprimer.type = ''button'';ButtonSupprimer.value = ''remove'';ButtonSupprimer.onclick=function(){formation.remov eChild(tablebody2)}cellSec10.appendChild(ButtonSupprimer);rowSec2.appendChild(cellSec10);tablebody2.appendChild(rowSec2);formation.appendChild(tablebody2);globalClaimLnsRowNum = globalClaimLnsRowNum + 1;}function calculateTab(n_line_no){var oForm = document.forms[0];alert(''line number = '' + n_line_no);oForm.elements[''2d_txt_total_line__'' + n_line_no].value =nz(oForm.elements[''2d_txt_unit_price__'' + n_line_no].value) *nz(oForm.elements[''2d_txt_quantity__'' + n_line_no].value);}function nz(s_val){var s_datatype = "undefined";if(s_val==null || s_val=='''' || isNaN(s_val) ||typeof(s_val)==s_datatype){//return isNaN(num)?0:num;return 0;}else{//alert(s_val);return parseFloat(s_val);}}function resetForm(){var oForm = document.forms[0];for (i=0; i<oForm.elements.length; i++){oForm.elements[i].value = "";}}function setLabel(s_message,s_label_name) {document.all(s_label_name).innerText = s_message;}//--></script><html><head></head><body><form method="post" action="" id="form1" name="form1"><table><tr><td width=''4%''><tr><td colspan=''6''> </td></tr><tr><td> </td><td><input type="button" name="Button2" value="change label"onclick=setlabel(''here is some different text'',''label_detail'');></td><td><input type="button" name="Button" value="calculate"onclick=calculateTab(''1'');></td><td colspan=''1'' align=''right''> </td><td><input name=''cmd_detail_new'' type=''button'' id=''cmd_detail_new''value=''add row [click here]'' onclick=detail_row();></td><td> </td><td colspan=''3'' align=''right''>total </td><td><input name=''2d_txt_detail_total'' type=''text''id=''2d_txt_detail_total'' value='''' size=''10''onChange=document.forms[0].elements[''txt_haschanged''].value =''yes'';></td><td width=''16%''>=EUR</td><td width=''30%''><input name=''2d_txt_detail_total_euro'' type=''text''id=''2d_txt_detail_total_euro'' value='''' size=''10''onChange=document.forms[0].elements[''txt_haschanged''].value=''yes'';></td></td></tr><tr><td colspan=''6''></td></tr></table></td></tr></table><table><tr><td height=''20'' valign=''top''><table width=''100%'' border=''1'' cellpadding=''0'' cellspacing=''0''valign=''top'' id=''formation''><tr><td width=''15%''> <b>GOODS</b></td><td width=''5%''> <b>UNIT PRICE</b></td><td width=''10%''> <b>CURRENCY</b></td><td width=''5%''> <b>QUANTITY</b></td><td width=''5%''> <b>TOTAL LINE</b></td><td width=''5%''> <b>UPLIFT (%)</b></td><td width=''5%''> <b>INCL. UPLIFT</b></td><td width=''5%''> <b>=EUR</b></td><td width=''5%''> <b> </b></td></tr><tr><td colspan=''10''><label id=''label_detail''>NO RECORDS FOUND</label></td></tr><input type=''text'' id=''2d_txt_detail_ids''name=''2d_txt_detail_ids'' value=''''><input type=''text'' id=''txt_update_ids'' name=''txt_update_ids''value=''''></table></td></tr></table></form></body></html>thanks for any help, kiep.s. the funtion setLabel that addresses: <label id=''label_detail''>fails for a reason unknown to me, any pointers on this too would begreatly appreciated.推荐答案''; sel2.appendChild(opt1); opt1 = document.createElement(''option''); opt1.value =''2''; if(opt1.value == s_currency_id){opt1。 setAttribute(''选择'', true);} opt1.innerHTML ='''STG''; sel2。 appendChild(opt1); opt1 = document.createElement(''option''); opt1.value =''3''; if(opt1.value == s_currency_id){opt1.setAttribute(''选择'', true);} opt1.innerHTML =''A'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''2'';if (opt1.value==s_currency_id){opt1.setAttribute(''sel ected'',true);}opt1.innerHTML=''」STG'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''3'';if (opt1.value==s_currency_id){opt1.setAttribute(''sel ected'',true);}opt1.innerHTML=''A''; sel2.appendChild(opt1); opt1 = document.createElement(''option''); opt1.value =''4''; if(opt1.value = = s_currency_id){opt1.setAttribute(''选择'', true);} opt1.innerHTML =''NZ'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''4'';if (opt1.value==s_currency_id){opt1.setAttribute(''sel ected'',true);}opt1.innerHTML=''NZ''; sel2.appendChild(opt1); opt1 = document.createElement(''option''); opt1.value ='''5''; if(opt1.value == s_currency_id){opt1.setAttribute(''sel ected'', true); } opt1.innerHTML =''BHAT''; sel2.appendChild(opt1); cellSec4.appendChild(sel2); rowSec2.appendChild(cellSec4); cellSec5 = document.createElement(''TD''); aTextBox = document .createElement(''input''); aTextBox.type =''text''; aTextBox.value = nz(s_quantity); aTextBox.size ='''5''; aTextBox.name =''2d_txt_quantity__''+ globalClaimLnsRowNum; cellSec5.appendChild(aTextBox); rowSec2.appendChild(cellSec5); cellSec6 = do cument.createElement(''TD''); aTextBox = document.createElement(''input''); aTextBox.type =''text''; aTextBox.value = nz(s_total_line); aTextBox.size ='''5''; aTextBox.name =''2d_txt_total_line__ ''+ globalClaimLnsRowNum; cellSec6.appendChild(aTextBox); rowSec2.appendChild(cellSec6); cellSec7 = document .createElement(''TD''); sel2 = document.createElement(''select''); sel2.name =''2d_cmb_uplift__''+ globalClaimLnsRowNum ; opt1 = document.createElement(''option''); opt1.value ='''100''; if(b) opt1.value == s_uplift){opt1.setAttribute(''selected'',true);} opt1.innerHTML ='''100%''; sel2 .appendChild(opt1); opt1 = document.createElement(''option''); opt1.value ='''105''; if(opt1.value == s_uplif t){opt1.setAttribute(''selected'',true);} opt1.innerHTML =''105%''; sel2.appendChild(opt1) ; opt1 = document.createElement(''option''); opt1.value =''110''; if(b) opt1.value == s_uplift){opt1.setAttribute(''selected'',true);} opt1.innerHTML =''110%''; sel2 .appendChild(opt1); opt1 = document.createElement(''option''); opt1.value =''0''; if(opt1.value == s_uplift){opt1.setAttribute(''selected'',true);} opt1.innerHTML =''other''; sel2.appendChild(opt1); cellSec7.appendChild(sel2); rowSec2.appendChild(cellSec7); cellSec8 = document.createElement(''TD''); aTextBox = document.createElement(''input''); aTextBox.type ='' text''; aTextBox.value = nz(s_incl_uplift); aTextBox.size =''3 '; aTextBox.name =''2d_txt_incl_uplift__''+ globalClaimLnsRowNum; cellSec8.appendChild(aTextBox); rowSec2.appendChild(cellSec8 ); cellSec9 = document.createElement(''TD''); aTextBox = document.createElement(''input''); aTextBox.type =''text''; aTextBox.value = nz(s_incl_uplift_euro); aTextBox.name =''2d_txt_incl_uplift_euro__'' + globalClaimLnsRowNum; aTextBox.size ='''5''; aTextBox.onchange = function(){calculateTab(globalCl aimLnsRowNum) ;} cellSec9.appendChild(aTextBox); rowSec2.appendChild(cellSec9); cellSec10 = document.createElement( ''TD''); ButtonSupprimer = document.createElement(''input''); ButtonSupprimer.type =''button''; ButtonSupprimer.value =''删除''; ButtonSupprimer.onclick = function() {formation.remov eChild(tablebody2)} cellSec10.appendChild(ButtonSupprimer); rowSec2.appendChild(cellSec10); tablebody2.appendChild(rowSec2); formation.appendChild(tablebody2); globalClaimLnsRowNum = globalClaimLnsRowNum + 1; } 函数calculateTab(n_line_no){ var oForm = document.forms [0]; alert( ''行号=''+ n_line_no); oForm.elements [''2d_txt_total_line__''+ n_line_no] .value = nz(oForm。 elements [''2d_txt_unit_price__''+ n_line_no] .value)* nz(oForm.elements [''2d_txt_quantity__''+ n_line_no] .value); } 函数nz(s_val){ var s_datatype =" undefined" ;; if(s_val == null || s_val ==''''|| isNaN(s_val)|| typeof(s_val)== s_datatype){ //返回isNaN(num)?0:num; 返回0; } else { // alert(s_val); 返回parseFloat(s_val ); } } 函数resetForm(){ var oForm = document。 form [0]; for(i = 0; i< oForm.elements.length; i ++){ oForm.elements [i] .value ="" ;; } } 函数setLabel(s_message,s_label_name){ 文件。 all(s_label_name).innerText = s_message; } // - > < / script> < html> < head> < / head> < body> < form method =" post"行动= QUOT;" ID = QUOT; form1的" name =" form1"> < table> < tr> < td width ='''4%' '> < tr> < td colspan ='''6''> < / td> < / tr> < tr> < td>& nbsp;< / td> ; < td>< input type =" button"名称= QUOT;将Button2" value =" change label" onclick = setlabel(''这里有一些不同的文字'',''label_detail'');> < / td> ; < td>< input type =" button"名称= QUOT;按钮和QUOT; value =" calculate" onclick = calculateTab(''1'');>< / td> < td colspan =''1'' align =''right''>& nbsp;< / td> < td> < input name =''cmd_detail_new''type = ''button''id =''cmd_detail_new'' value =''添加行[点击此处]''onclick = detail_row();> < / td> < td>& nbsp;< / td> < td colspan =''3''align =''right''> ;总计< / td> < td> <输入名称=''2d_txt_detail_total''type =''text'' id =''2d_txt_detail_total''value =''''size =''10'' onChange = document.forms [0] .elements [''txt_haschanged'']。value = ''是';;> < / td> < td width =''16%''> = EUR< / td> < td width =''30%''> < input name =''2d_txt_detail_to tal_euro''type =''text'' id =''2d_txt_detail_total_euro''value =''''size =''10'' onChange = document。 forms [0] .elements [''txt_haschanged'']。value =''yes'';>< / td> < / td> < / tr> < tr> < td colspan ='''6''>< / td> < / tr> < / table> < / td> < / tr> < / table> < table> < tr> < td height ='''20''valign =''top''> < table width =''100%''border =''1''cellpadding =''0''cellspacing =''0'' valign =''top''id =''形成''> < tr> < td width =''15%''>& nbsp;< b> GOODS< / b>< / td> < td width ='''5%'' >& nbsp;< b> UNIT PRICE< / b>< / td> < td width =''10%''>& nbsp;< b> CURRENCY< / b>< / td> < td width ='' 5%''>& nbsp;< b> QUANTITY< / b>< / td> < td width =''5%''>& nbsp;< ; b> TOTAL LINE< / b>< / td> < td width =''5%''>& nbsp;< b> UPLIFT(%)< / b>< / td> < td width =''5%''>& nbsp;< b> INCL。 UPLIFT< / b>< / td> < td width =''5%''>& nbsp;< b> = EUR< / b>< / td> < td width =''5%''>& nbsp;< b>& nbsp;< / b>< / td> < / tr> < tr> < td colspan =''10''> < label id =''label_detail''>没有记录找到< / label> < / td> < / tr> < ; input type =''text''id =''2d_txt_detail_ids'' name =''2d_txt_detail_ids''value =''''> < input type =''text''id =''txt_update_ids''name =''txt_update_ids'' value =''''> < / table> < / td> < / tr> < / table> < / form> < / body> < / html> 感谢您的帮助,kie ps解决了以下问题的功能setLabel:< label id =''label_detail''> 由于我不知道的原因而失败,对此的任何指针都将是 赞赏。'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''5'';if (opt1.value==s_currency_id){opt1.setAttribute(''sel ected'',true);}opt1.innerHTML=''BHAT'';sel2.appendChild(opt1);cellSec4.appendChild(sel2);rowSec2.appendChild(cellSec4);cellSec5=document.createElement(''TD'');aTextBox=document.createElement(''input'');aTextBox.type = ''text'';aTextBox.value = nz(s_quantity);aTextBox.size = ''5'';aTextBox.name = ''2d_txt_quantity__'' + globalClaimLnsRowNum;cellSec5.appendChild(aTextBox);rowSec2.appendChild(cellSec5);cellSec6=document.createElement(''TD'');aTextBox=document.createElement(''input'');aTextBox.type = ''text'';aTextBox.value = nz(s_total_line);aTextBox.size = ''5'';aTextBox.name = ''2d_txt_total_line__'' + globalClaimLnsRowNum;cellSec6.appendChild(aTextBox);rowSec2.appendChild(cellSec6);cellSec7=document.createElement(''TD'');sel2=document.createElement(''select'');sel2.name=''2d_cmb_uplift__'' + globalClaimLnsRowNum;opt1=document.createElement(''option'');opt1.value=''100'';if (opt1.value==s_uplift){opt1.setAttribute(''selected '', true);}opt1.innerHTML=''100%'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''105'';if (opt1.value==s_uplift){opt1.setAttribute(''selected '', true);}opt1.innerHTML=''105%'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''110'';if (opt1.value==s_uplift){opt1.setAttribute(''selected '', true);}opt1.innerHTML=''110%'';sel2.appendChild(opt1);opt1=document.createElement(''option'');opt1.value=''0'';if (opt1.value==s_uplift){opt1.setAttribute(''selected '', true);}opt1.innerHTML=''other'';sel2.appendChild(opt1);cellSec7.appendChild(sel2);rowSec2.appendChild(cellSec7);cellSec8=document.createElement(''TD'');aTextBox=document.createElement(''input'');aTextBox.type = ''text'';aTextBox.value = nz(s_incl_uplift);aTextBox.size = ''3'';aTextBox.name = ''2d_txt_incl_uplift__'' + globalClaimLnsRowNum;cellSec8.appendChild(aTextBox);rowSec2.appendChild(cellSec8);cellSec9=document.createElement(''TD'');aTextBox=document.createElement(''input'');aTextBox.type = ''text'';aTextBox.value = nz(s_incl_uplift_euro);aTextBox.name = ''2d_txt_incl_uplift_euro__'' +globalClaimLnsRowNum;aTextBox.size = ''5'';aTextBox.onchange=function(){calculateTab(globalCl aimLnsRowNum);}cellSec9.appendChild(aTextBox);rowSec2.appendChild(cellSec9);cellSec10=document.createElement(''TD'');ButtonSupprimer=document.createElement(''input'');ButtonSupprimer.type = ''button'';ButtonSupprimer.value = ''remove'';ButtonSupprimer.onclick=function(){formation.remov eChild(tablebody2)}cellSec10.appendChild(ButtonSupprimer);rowSec2.appendChild(cellSec10);tablebody2.appendChild(rowSec2);formation.appendChild(tablebody2);globalClaimLnsRowNum = globalClaimLnsRowNum + 1;}function calculateTab(n_line_no){var oForm = document.forms[0];alert(''line number = '' + n_line_no);oForm.elements[''2d_txt_total_line__'' + n_line_no].value =nz(oForm.elements[''2d_txt_unit_price__'' + n_line_no].value) *nz(oForm.elements[''2d_txt_quantity__'' + n_line_no].value);}function nz(s_val){var s_datatype = "undefined";if(s_val==null || s_val=='''' || isNaN(s_val) ||typeof(s_val)==s_datatype){//return isNaN(num)?0:num;return 0;}else{//alert(s_val);return parseFloat(s_val);}}function resetForm(){var oForm = document.forms[0];for (i=0; i<oForm.elements.length; i++){oForm.elements[i].value = "";}}function setLabel(s_message,s_label_name) {document.all(s_label_name).innerText = s_message;}//--></script><html><head></head><body><form method="post" action="" id="form1" name="form1"><table><tr><td width=''4%''><tr><td colspan=''6''> </td></tr><tr><td> </td><td><input type="button" name="Button2" value="change label"onclick=setlabel(''here is some different text'',''label_detail'');></td><td><input type="button" name="Button" value="calculate"onclick=calculateTab(''1'');></td><td colspan=''1'' align=''right''> </td><td><input name=''cmd_detail_new'' type=''button'' id=''cmd_detail_new''value=''add row [click here]'' onclick=detail_row();></td><td> </td><td colspan=''3'' align=''right''>total </td><td><input name=''2d_txt_detail_total'' type=''text''id=''2d_txt_detail_total'' value='''' size=''10''onChange=document.forms[0].elements[''txt_haschanged''].value =''yes'';></td><td width=''16%''>=EUR</td><td width=''30%''><input name=''2d_txt_detail_total_euro'' type=''text''id=''2d_txt_detail_total_euro'' value='''' size=''10''onChange=document.forms[0].elements[''txt_haschanged''].value=''yes'';></td></td></tr><tr><td colspan=''6''></td></tr></table></td></tr></table><table><tr><td height=''20'' valign=''top''><table width=''100%'' border=''1'' cellpadding=''0'' cellspacing=''0''valign=''top'' id=''formation''><tr><td width=''15%''> <b>GOODS</b></td><td width=''5%''> <b>UNIT PRICE</b></td><td width=''10%''> <b>CURRENCY</b></td><td width=''5%''> <b>QUANTITY</b></td><td width=''5%''> <b>TOTAL LINE</b></td><td width=''5%''> <b>UPLIFT (%)</b></td><td width=''5%''> <b>INCL. UPLIFT</b></td><td width=''5%''> <b>=EUR</b></td><td width=''5%''> <b> </b></td></tr><tr><td colspan=''10''><label id=''label_detail''>NO RECORDS FOUND</label></td></tr><input type=''text'' id=''2d_txt_detail_ids''name=''2d_txt_detail_ids'' value=''''><input type=''text'' id=''txt_update_ids'' name=''txt_update_ids''value=''''></table></td></tr></table></form></body></html>thanks for any help, kiep.s. the funtion setLabel that addresses: <label id=''label_detail''>fails for a reason unknown to me, any pointers on this too would begreatly appreciated. 这篇关于由createElement和appendChild在表中计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-13 17:44