javascript功能中的peoblem? [英] peoblem in javascript function?

查看:69
本文介绍了javascript功能中的peoblem?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有javascript函数,可验证gridview页脚行中的两个文本框.
这是我的功能
函数validateNetWeight(){
Page_ClientValidate("gvOrnament");
如果(Page_IsValid)
{
var netWeight = document.getElementById(''<%=((TextBox)gvLoanOrnaments.FooterRow.FindControl("txtNet")).ClientID%>'').value;
var GrossWeight = document.getElementById(''<%=((TextBox)gvLoanOrnaments.FooterRow.FindControl("txtGross")).ClientID%>'').value;
if(netWeight> GrossWeight){
alert(净重应小于或等于毛重");
返回false;
}
其他
{
返回true;
}
}
其他
{
返回false;
}
}
问题在于它是在比较数字的第一位数而不是整数.
例如:如果我们将90的毛重和80的净重放进去,那是可以接受的. 但是如果您将毛重100和净重90放进去,则会显示警报
它正在检查第一位数字100和第一位数字90,因此9大于1,因此显示警报

I have javascript function to validate two text boxes which are in gridview footer row.
here is my function
function validateNetWeight() {
Page_ClientValidate("gvOrnament");
if (Page_IsValid)
{
var netWeight = document.getElementById(''<%=((TextBox)gvLoanOrnaments.FooterRow.FindControl("txtNet")).ClientID %>'').value;
var GrossWeight = document.getElementById(''<%=((TextBox)gvLoanOrnaments.FooterRow.FindControl("txtGross")).ClientID%>'').value;
if (netWeight > GrossWeight) {
alert("Net weight should be less than or equal to gross weight");
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
The problem is it is comparing first digit of number not entire number.
Ex: If we put 90 in grossweight and 80 in net weight it is accepting.
but if you put 100 in grossweight and 90 in net weight it is showing the alert
It is checking first digit of 100 and first digit 90 so 9 is greater than 1 so it s showing the alert

推荐答案



您的问题很清楚.

您要输入的净重和毛重的值是字符串.

如果您使用的是<或>运算符,那么它将无法正确比较


使用以下


Hi,

Your issue quite clear.

The values you are getting into netweight and grossweight are strings.

If you are using < or > operator then it will not compare properly


use the following


if (parseFloat(netWeight) > parseFloat(GrossWeight))







or

if (parseInt(netWeight) > parseInt(GrossWeight))



希望对您有帮助



Hope this helps


这篇关于javascript功能中的peoblem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆