jquery输入字段相加,最大总计
我正在尝试获取这段代码并向其中添加一段代码。我希望 #total 有一个最大数量。我什至不知道如何处理这个问题。我查看了查询文档以添加验证或其他内容,但这不是我想要的。任何帮助将不胜感激。 http://jsfiddle.net/anderskitson/VVkzG/1/
JQUERY:
$('#the_input_id').keyup(function() {
updateTotal();
});
$('#the_input_id1').keyup(function() {
updateTotal();
});
var updateTotal = function() {
var input1 = parseInt($('#the_input_id').val());
var input2 = parseInt($('#the_input_id1').val());
if (isNaN(input1) || isNaN(input2)) {
$('#total').text('');
} else {
$('#total').text(input1 + input2);
}
};
I am trying to take this code and add one piece to it. I would like the #total to have a maximum number. I am not even sure how to approach this one. I have looked around the query documentation at adding a validation or something but it wasn't what I wanted. Any help would be greatly appreciated. http://jsfiddle.net/anderskitson/VVkzG/1/
JQUERY:
$('#the_input_id').keyup(function() {
updateTotal();
});
$('#the_input_id1').keyup(function() {
updateTotal();
});
var updateTotal = function() {
var input1 = parseInt($('#the_input_id').val());
var input2 = parseInt($('#the_input_id1').val());
if (isNaN(input1) || isNaN(input2)) {
$('#total').text('');
} else {
$('#total').text(input1 + input2);
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jsfiddle.net/VVkzG/2
HTML
JavaScript
jsfiddle.net/VVkzG/2
HTML
Javascript