像Spinner这样的jquery的textinput的增量值

问题描述:

尝试使用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 );
  } );
} );