增加文本框的值

时间:2013-11-29 07:23:41

标签: javascript jquery html css

enter image description here

如何在keyup / down或tap上增加和减少文本框的值。 example

HTML: -

<div class="right-content" id="rc-0" style="height: 250px;">
  <div class="right-cont-main" id="rcm-0" style="height: 250px;">
    <div class="scroll-line" id="sl-0" style="height: 250px;">
      <div class="scroll-top" id="st-0"></div>
      <div class="scroll-mid" id="sm-0" style="height: 248px;"></div>
      <div class="scroll-bottom" id="sb-0"></div>
    </div>
    <div class="scroll-textbox" id="stb-0" style="margin-top: -138px;">
      <input type="text" class="scroll-textbox-input right-input" value="50" id="in-1" name="txt">
    </div>
  </div>
</div>
 </div>        
</div>

2 个答案:

答案 0 :(得分:1)

你的意思是:

$( document ).on( "keydown", ".right-input", function(ev) {
   if (ev.which == 38 || ev.which == 104) { //for up
        $this.val((parseInt($this.val()) + 1));
    } else if (ev.which == 40 || ev.which == 98) { //for down
        $this.val((parseInt($this.val()) - 1));
    }
});

答案 1 :(得分:1)

我编辑了你的源码jsFiddle: http://jsfiddle.net/5aJzD/14/

if (e.which == 38 || e.which == 104) {
    height++;
} else if (e.which == 40 || e.which == 98) {
    height--;
}

height=parseInt(height);
$("#in-1").val(height);