使用 jquery 像微调器一样增加 textinput 的值 [英] Increment value of textinput with jquery like spinner
问题描述
尝试使用 Jquery 创建一个简单的微调器效果,即两个按钮(向上和向下)和一个文本字段.向上按钮增加值,而向下按钮减少值.递增步数 + 或 - 1.
Trying to create a simple spinner effect with Jquery, i.e. two buttons (up & down) with a text field. The upbutton increases the value while the down button decreses the value. increment steps + or - 1.
作为 ui.spinner 的任何建议都是最明确的.不工作,我是 jquery 的新手.发霉的东西$(#up).click (function (/*SOMETHING GOES IN HERE but what?*/))
和#down 也是如此.两者都设置调整输入文本字段说 id #test 如上.
Any suggestions as ui.spinner is most def. not working and I am new to jquery. musty be something like
$(#up).click (function ( /*SOMETHING GOES IN HERE but what?*/ ))
and likewise for #down. both to set adjust the input text field say id #test as above.
推荐答案
可能是这样的:
$(document).ready( function() {
var el = $('#test');
function change( amt ) {
el.val( parseInt( el.val(), 10 ) + amt );
}
$('#up').click( function() {
change( 1 );
} );
$('#down').click( function() {
change( -1 );
} );
} );
这篇关于使用 jquery 像微调器一样增加 textinput 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!