How to cancel or reset specific form values?

后端 未结 5 1985
感情败类
感情败类 2021-01-23 00:29

I have this code


  
    

<
5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-23 00:53

    When you load the page you will have to collect all the values in a javascript array

    var defaults = new Array();
    var elements;
    window.onload = function(){
        elements = document.getElementsByTagName("input");
        for (i=0; i

    and return to defaults when the button cancel is clicked

    var cancel = document.getElementById('cancel');
    cancel.onclick = function() {
        for(i=0; i

    Edit: for reset button you can use

    
    

    Edit 2: if you want to reset only the value if the input c you can use this:

    var cancel = document.getElementById('cancel');
    cancel.onclick = function() {
        for(i=0; i

提交回复
热议问题