简体   繁体   English

在两个.html页面之间传递变量

[英]pass variable between two .html pages

I basically have a search box, I am trying to get the value inserted and use on a separate /results.htm screen via the submit button. 我基本上有一个搜索框,我试图插入值,并通过提交按钮在单独的/results.htm屏幕上使用。 I've been able to get and process the results within the same page; 我已经能够在同一页面中获取和处理结果; but I am trying to do this after redirecting to a new page 但我尝试在重定向到新页面后执行此操作

/search.html /search.html

 <script>
    jQuery(document).ready(function() {
        jQuery("#submit").click(function() {
            var ZipSearch = jQuery("#Zipcode").val();
        });
    });
    </script>
    <div class="search_bar">
        <form action=""><input type="text" name="Zipcode" id="Zipcode" value="" maxlength="5" placeholder="Zipcode">
        <input type="button" name="submit" id="submit" value="Submit"/></form>
    </div>

Want to keep input value content from /search.htm within a variable on next page, separate, /results.htm 想要将来自/search.htm的输入值内容保留在下一页的单独变量/results.htm中

How can I keep the user input value and use on my separate 'results' page? 如何保持用户输入值并在单独的“结果”页面上使用?

Remove all the JavaScript from search.htm . search.htm中删除所有JavaScript。 There's no point in writing custom software to do things HTML has built-in. 编写自定义软件来完成HTML内置的事情是没有意义的。

Set the action of the form to the URL of the second page ( action="/results.htm" ). 将表单的action设置为第二页的URL( action="/results.htm" )。

Change the button to a submit button ( type="submit" ) 将按钮更改为一个提交按钮( type="submit"

Read the data from the query string ( location.search in JavaScript or $_GET in PHP). 从查询字符串(JavaScript中的location.search或PHP中的$_GET )读取数据。

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

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