Saturday, December 27, 2014

[jQuery] Cach reset form hoac reset value input tren form

Cach 1:

Doing this task with jQuery is really easy:
$('#FormID').each (function(){
  this.reset();
});
The thing is, that the code above iterates through each element of the form, and calls to the DOM “reset” JavaScript method. In fact, the “reset” function does not exist in jQuery.
It would be much more simple to do something like $(“#FormID”).reset(). Fortunately creating that function in jQuery only will take a minute of programming:
jQuery.fn.reset = function () {
  $(this).each (function() { this.reset(); });
}
Using the code above, reseting a form would be just one call (as desired):
$("#FormID").reset();

Cach 2:

<input type="button" onclick="this.form.reset();">
Cach 3:

function reset(){
    $('input[type=text]').val('');  
    $('#textarea').val(''); 
    $('input[type=select]').val('');
    $('input[type=radio]').val('');
    $('input[type=checkbox]').val('');  
}

No comments:

Post a Comment