html中的button按钮调用js函数和提交表单传递参数

xiaoxiao2021-02-28  21

1.button的type设置为button 而不用submit,并添加onclick方法调用js函数

<input type="button" name="confirmAlter" value="确认修改" οnclick="changeInfo(form1.code,form1.name,form1.detail,form1.count)"/>

2.传到js函数中,然后提交表单到servlet并传递参数

<script language="javascript"> function changeInfo(code,name,detail,count){ var string1 = code.value; var string2 = name.value; var string3 = detail.value; var number = count.value; //alert("hello word!");

document.getElementById('form1').action="workServlet?action=alterInfo&code="+string1+"&name="+string2+"&detail="+string3+"&count="+number; document.getElementById("form1").submit(); } </script>

3.在servlet中调用request.getParameter()方法即可获取参数

转载请注明原文地址: https://www.6miu.com/read-2000004.html

最新回复(0)