您的位置:首页 > Web前端 > JavaScript

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

2018-02-02 13:41 3007 查看
1.button的type设置为button 而不用submit,并添加onclick方法调用js函数

<input type="button" name="confirmAlter" value="确认修改" onclick="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()方法即可获取参数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: