栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

当其中一种发生onchange时,以两种形式发布参数

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

当其中一种发生onchange时,以两种形式发布参数

提交表单时,仅该表单中的字段会根据请求发送。

您可以只使用一种表单(包含所有字段),也可以使用Javascript,然后再提交以将值从一种表单复制到另一种表单的隐藏元素。

编辑: 这是一个小JS示例:

<!-- test.html --><html>  <head>    <script type="text/javascript">      function doCopyAndThenSubmit() {        var sourceInput = document.getElementById("source");        //destination should be the hidden field, made it text to have a visual on the operation        var destinationInput = document.getElementById("destination");        destinationInput.value = sourceInput.value;       //watch the address bar after the OK       alert("Did the copy, press OK for the submit");       document.forms["yourForm"].submit();      }    </script>  </head>  <body>    Add some text in source and change the value in the select<br/>    <form action="test.html" method="GET" name="yourForm">      <select onchange="doCopyAndThenSubmit()">        <option value="x">some value</option>        <option value="y">some other</option>      </select>      <br/>Source:      <!-- id must be unique in the entire document (don't confound with name) -->      <input name="src" id="source" type="text" value="" />      <br/>Destination:      <input name="dest" id="destination" type="text" value="" />    </form>    </body></html>

通常,您将拥有具有相同值的name和id属性,以便于跟踪(而不是先按id然后按名称引用一次输入);我使用了不同的值来加强差异。当然,您将以一种形式出现源,而以另一种形式出现目的地。

<form name="form1" ...>  ...  <input name="source" id="source" type="text" value="" /></form><form name="form2" ...>  ...  <input name="destination" id="destination" type="hidden" value="" /></form>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/409126.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号