本文介绍了Javascript函数在Chrome中提供NaN,但在IE中运行良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好 我有以下javascript代码在IE中正常工作。但是,当我在Chrome中加载此页面时,字段总数会被NaN填充。任何帮助将不胜感激.. 函数Addvalue(){ var gv = document.getElementById( <%= Grid_Insert.ClientID%>); var gvRowCount = gv.rows.length; var total = 0 ; for (i = 1 ; i < ; gvRowCount; i ++){ for (j = 2 ; j < 15 ; j ++){ var a = parseInt(gv.rows [i] .cells [j] .childNodes [ 0 ]。 value ); if (j < 14 ) { if (!isNaN(a)) { total = total + parseInt(gv .rows [i] .cells [j] .childNodes [ 0 ]。 value ); } } 如果(j == 14 ){ gv.rows [i] .cells [j] .innerText = total; } } } } 行 如果(!isNaN(a) ))) 我在 IE但是Retrn false 我在中运行 Chrome .. 请帮助 解决方案 您的测试 if(value != NaN)不是正确的测试。 使用: if(!isNaN(value)) REF: http://www.w3schools.com/jsref/ jsref_isnan.asp [ ^ ] Hi EverybodyI have the following javascript code that works fine in IE . But when i load this page in chrome the fields total get filled with NaN. Any help would be appreciated.. function Addvalue() { var gv = document.getElementById("<%=Grid_Insert.ClientID %>"); var gvRowCount = gv.rows.length; var total = 0; for (i = 1; i < gvRowCount; i++) { for (j = 2; j < 15; j++) { var a = parseInt(gv.rows[i].cells[j].childNodes[0].value); if (j < 14) { if (!isNaN(a)) { total = total + parseInt(gv.rows[i].cells[j].childNodes[0].value); } } if (j == 14) { gv.rows[i].cells[j].innerText = total; } } } }the lineif (!isNaN(a)) returns true when i Run my page in IE but Retrn false when I run in Chrome..Pls Help 解决方案 Your test if(value != NaN) is not the proper test.Use: if(!isNaN(value) )REF: http://www.w3schools.com/jsref/jsref_isnan.asp[^] 这篇关于Javascript函数在Chrome中提供NaN,但在IE中运行良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-15 12:06