0

我在 datalist 中有一个输入

<input type="text" value="1" id="txtcount">

我想在文本更改时获得它的新价值。

我使用此代码,但不适合我。

<script>
//look no global needed:)

$(document).ready(function(){
    // Get the initial value
   var $el = $('#txtcount');
   $el.data('oldVal',  $el.val() );


   $el.change(function(){
        //store new value
        var $this = $(this);
        var newValue = $this.data('newVal', $this.val());
   })
   .focus(function(){
        // Get the value when input gains focus
        var oldValue = $(this).data('oldVal');
   });
});

4

2 回答 2

0

这个怎么样

$('#txtcount').change(function() { ... });

或这个

$("#txtcount").keypress(function() { .......});

或这个

$('#txtcount').keyup(function() {..........});
于 2012-05-15T06:40:57.670 回答
0

用这个 :-

$('#txtcount').keyup(function(event) {
  if (event.keyCode == 13) {
    var message =  $('#txtcount').val();
    alert(message);
  } else {
    return true;
  }
});

或者您可以获取 TextField 的“onTextChanged”事件的值

于 2012-05-15T06:16:09.370 回答