本文介绍了字符串的值???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个包含40个文本框的表单(默认值为每个= 0)。我想 评估每个框以查看该值是否仍然为零,如果是,我将b $ b想要将其添加到零计数。盒子名称是L411至L419, L421至L429,L431至L439和L431至L439。和L441至L449。 例如: L41 - 002000500 L42 - 000030000 L43 - 000000000 L44 - 000000000 我通过几个嵌套for循环构造控件名称 并且一切都很好(构造的string =" MyForm.L411.value")。 当我将其插入到If语句中以获取控件的值时, 一切都会死亡。这是我的If: for(var j = 1; j< 5; j ++) { rowString = L4; //建立L41 rowString = rowString + j; for(var x = 1; x { //建立L411 rowString = rowString + x; //构建MyForm.L411.value rowString =" MyForm。" + rowString +" .value" // alert显示MyForm.L411.value - 没有引号 // alert(rowString); if(rowString =" 0") { zeroCount ++: } rowString =" L4" + j; } } 如何根据构建的字符串测试控件的值? 很多tia'的 ckI have a form with 40 text boxes (default of each = 0). I want toevaluate each box to see if the value is still zero, and if it is, Iwant to add it to a "Zero Count". The box names are "L411 thru L419","L421 thru L429", "L431 thru L439" and "L441 thru L449".Example:L41 - 002000500L42 - 000030000L43 - 000000000L44 - 000000000I have construct the control name thru a couple of nested for loopsand all is well (constructed string = "MyForm.L411.value").When I plug this into an If statement to get the value of the control,everything dies. Here is my If:for(var j = 1; j < 5; j++){rowString = "L4";// builds L41rowString = rowString + j;for(var x = 1; x < 10; x++){// builds L411rowString = rowString + x;// Builds MyForm.L411.valuerowString = "MyForm." + rowString + ".value"//alert shows "MyForm.L411.value" - without quotes//alert(rowString);if( rowString = "0"){zeroCount++:}rowString = "L4" + j;}}How can I test the value of a control, based on a string built?Many tia''sck推荐答案 - Rob--Rob (36,而不是40,文本输入)。 var i ,j,nZeroCount,oForm,oCurElem,oCurVal; oForm = document.forms [''MyForm'']; nZeroCount = 0; for(i = 1; i< 10; i ++){ for(j = 1; j< 5; j ++){ oCurElem = oForm.elements [ " L4" + j + i]; if(oCurElem){ oCurVal = oCurElem.value; if(!isNaN(oCurVal)& & parseInt(oCurVal,10)== 0){ nZeroCount ++; } } } } ciao,dhgm(That are 36, not 40, text inputs).var i, j, nZeroCount, oForm, oCurElem, oCurVal;oForm = document.forms[''MyForm''];nZeroCount = 0;for (i=1; i<10; i++) {for (j=1; j<5; j++) {oCurElem = oForm.elements["L4" + j + i];if (oCurElem) {oCurVal = oCurElem.value;if (!isNaN(oCurVal) && parseInt(oCurVal, 10) == 0) {nZeroCount++;}}}}ciao, dhgm 如果您使用过JSLint,它会提醒您注意这个语句。你 可能意味着 if(rowString ==" 0"){ 见 http://www.JSLint.com 这篇关于字符串的值???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-12 01:34