简体   繁体   English

如何在表单中设置动作属性以转到同一HTML页面中的另一表单,以及如何将第一种形式的值转换为第二种形式?

[英]how to set action property in a form to go to another form in same html page and how to get values in first form into second form?

I have 2 forms in same html page.one form get the values and then these values must be pass to the second form.But I don't know how to go to the second form through the first form. 我在同一个html页面中有2个表单。一个表单获取值,然后必须将这些值传递给第二个表单。但是我不知道如何通过第一个表单进入第二个表单。

when using action="#" , I can go to same page. 使用action =“#”时,我可以转到同一页面。 but how to go to the second form after get values from first form?Can someone please help me? 但是从第一种形式获取值后如何去第二种形式?有人可以帮我吗?

Form's action property is to be used when you are sending your form data to server. 将表单数据发送到服务器时,将使用Form的action属性。 In your case you can do the copying client-side (by using JavaScript) and you can omit the first form tag altogether. 在您的情况下,您可以(通过使用JavaScript)在客户端进行复制,并且可以完全省略第一个form标签。

See the example below. 请参见下面的示例。

 document.getElementById('first_form_submit').addEventListener('click', function(event){ event.preventDefault(); document.getElementById('second_form_input').value = document.getElementById('first_form_input').value; // do the same for other form fields that you need to copy }); 
 .form { padding: 1em; background-color: #eee; margin-bottom: 1em; } 
 <div id="first_form" class="form"> <input type="text" id="first_form_input" /> <button id="first_form_submit">Send values to second form</button> </div> <form method="post" action="some-url" class="form"> <input type="text" id="second_form_input" name="some_name" /> </form> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM