jQuery的正负增量器 [英] Jquery Plus/Minus Incrementer
本文介绍了jQuery的正负增量器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想拥有一个客户端的Plus/Minus系统,用户可以单击加号,并且值增加1,减去,值减小1,该值永远不会低于零,并且应该从0开始有没有一种方法可以简单地在jquery中做到这一点?所有的jquery插件都会在OTT位置查看该操作.
I want to have a client side Plus / Minus system where a user can click the plus and a value is incremented by 1, minus and the value is decreased by 1, the value should never go below zero and should start on 0. Is there a way to do this simply in jquery? All the jquery plugins look at bit OTT for this operation.
任何帮助,谢谢.
推荐答案
类似这样的东西:
HTML:
<a id="minus" href="#">-</a>
<span id="value">0</span>
<a id="plus" href="#">+</a>
JavaScript:
Javascript:
$(function(){
var valueElement = $('#value');
function incrementValue(e){
valueElement.text(Math.max(parseInt(valueElement.text()) + e.data.increment, 0));
return false;
}
$('#plus').bind('click', {increment: 1}, incrementValue);
$('#minus').bind('click', {increment: -1}, incrementValue);
});
这篇关于jQuery的正负增量器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文