日期:2014-05-17  浏览次数:20686 次

html button
HTML code

<form action="" method="post">
     <input type="button" onclick="metho()">
</form>


metho()方法实现提交表单,并使页面跳至servlet,能实现吗

------解决方案--------------------
给form加个id,用form提交,是这个意思么?
HTML code

<script type="text/javascript">
function metho() {
        var dForm = document.getElementById("dForm");
        dForm.action = "process.do";
        dForm.submit();
    }
</script>

<form action="" method="post" id="dForm>
     <input type="button" onclick="metho()">
</form>

------解决方案--------------------
HTML code
<script type="text/javascript">
function metho() {
        var dForm = documentforms[0];
        dForm.action = "url";
        dForm.submit();
    }
</script>

<form action="" method="post">
     <input type="button" onclick="metho()">
</form>

------解决方案--------------------
<script type="text/javascript">
function metho() {
var dForm = document.getElementById("dForm");
dForm.action = "process.do";
dForm.submit();
}
</script>

<form action="" method="post" id="dForm>
<input type="button" onclick="metho()">
</form>



-->等价于

<form action="process.do" method="post" id="dForm>
<input type="submit" />
</form>

上面的绕道到js里面提交到process.do