Adding POST parameters before submit

前端 未结 7 899
情深已故
情深已故 2020-11-27 11:39

I\'ve this simple form:

7条回答
  •  执念已碎
    2020-11-27 12:09

    you can do this without jQuery:

        var form=document.getElementById('form-id');//retrieve the form as a DOM element
    
        var input = document.createElement('input');//prepare a new input DOM element
        input.setAttribute('name', inputName);//set the param name
        input.setAttribute('value', inputValue);//set the value
        input.setAttribute('type', inputType)//set the type, like "hidden" or other
    
        form.appendChild(input);//append the input to the form
    
        form.submit();//send with added input
    

提交回复
热议问题