像Spinner这样的jquery的textinput的增量值 [英] Increment value of textinput with jquery like spinner

查看:103
本文介绍了像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 );
  } );
} );

这篇关于像Spinner这样的jquery的textinput的增量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆