JS可以通过document.testform.submit()提交名称/值对吗? ? 或者是否必须通过html标签提交,例如

<INPUT TYPE="text" NAME="inputbox1" VALUE="This is such a great form!" SIZE=50><P>
有帮助吗?

解决方案

通常,您包含<!> lt; input type = <!> quot; hidden <!> quot; <!> gt;在表单中,并在事件处理程序提交之前设置所需的值。

<form method="post" action="thing" id="sandwich"><fieldset>
    <input type="text" name="inputbox1" value="This is such a great form!" />
    <input type="hidden" name="jsremark" />
</fieldset></form>

<script type="text/javascript">
    document.getElementById('sandwich').onsubmit= function() {
        this.elements.jsremark.value= 'Secretly it aint that great';
        return true;
    }
</script>

其他提示

不,你必须使用javascript

将自己混入JSON

使用jquery非常简单:

$("#formid").bind("submit", function(){
 var str = $("#formid").serialize();
 $.post("url?"+str);
 return false;
}

您可以仅使用JS设置ajax请求的发布数据。

使用jQuery很简单:

$.post(url, {"name":"value"})
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top