本文介绍了IF Greater无法在JS中正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个数字输入字段,当用户停止输入时,以下内容将运行.我正在做的是检查输入的数字是否大于输入b的数字,以及是否显示错误.
I have 2 numeric input fields and the below runs when the user stops inputting. What I am doing is checking that input a number is not bigger than input b and if it is show error.
问题是计算进行得不好.例如,如果a为200且b为100,则有效,但如果a为200且b为5,则无效.
The issue is that calculation is not happening well. For instance it works if a is 200 and b is 100 but not if a is 200 and b is 5
不确定为什么...,所以将不胜感激.
Not sure why... so any help would be greatly appreciated.
$("#input_6_23, #input_6_24").on({
blur: function() {
var a = document.getElementById("input_6_23").value;
var b = document.getElementById("input_6_24").value;
if(a > b) {
alert(a is bigger than b);
}
}
});
推荐答案
工作正常吗?
jQuery(document).ready(function($){
$("#input_6_23, #input_6_24").on('blur',function() {
check();
});
function check(){
var a = Number($("#input_6_23").val());
var b = Number($("#input_6_24").val());
if(a > b) {
alert(a+' is bigger than '+b);
} else {
alert("error");
}
}});
这篇关于IF Greater无法在JS中正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!