0

我有这样的代码:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
  $(document).ready(function(){
      var my_id = 'iddate';

      $('#'+ my_id).bind('keyup',function(e){ // Listener for key pressing in the field.
          var inputValue = document.getElementById( my_id ).value;
          // And etc...
      })
  });
</script>

这里我使用了 JQuery。但问题是我不能再使用它了。可以用javascript重写吗?

4

2 回答 2

1

是的,您可以,例如:

window.onload = function() {
  var my_id = 'iddate';

  document.getElementById( my_id ).onkeyup = function(e){ // Listener for key pressing in the field.
      var inputValue = document.getElementById( my_id ).value;
      // And etc...
  };
}

或通过使用addEventListener

document.getElementById( my_id ).addEventListener('click', function(e){ // Listener for key pressing in the field.
      var inputValue = document.getElementById( my_id ).value;
      // And etc...
}, false); 
于 2012-07-20T12:40:42.900 回答
0

或者你也可以这样做,

window.onload = function(){
   var my_id = 'iddate';
      document.getElementById( my_id ).onkeyup = function(e){ // Listener for key pressing in the field.
      var inputValue = document.getElementById( my_id ).value;
     };
}
于 2012-07-20T12:43:37.597 回答