提交来自javascript的名称/值对? [英] Submit name value pair from javascript?

查看:49
本文介绍了提交来自javascript的名称/值对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JS是否可以通过document.testform.submit();提交名称/价位对? ? 还是必须通过html标签提交,例如

Can JS submit name/vale pairs through a document.testform.submit(); ? or does it have to be submitted through the html tags, for example

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

推荐答案

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

Typically you include an <input type="hidden"> in the form, and set the value you want in the event handler before it gets submitted.

<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的名称/值对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆