javascript - 如何在 JavaScript 中使用查询字符串?

标签 javascript php jquery html

我已经创建了计算器项目。我只有两页。现在我的问题如何将输入字段值传递到另一个页面?尝试了太多方法但不起作用。

如何将输入字段值从一个页面传递到另一页面?

我的输入字段代码看起来像

<p class="pull-right">DPA Minimum Buyer Contribution<br /></p>
    <div class="row">
        <div class="col-md-3">
        </div>
        <div class="col-md-6" style="padding-right:1%">
            <input type="text" id="txtLocationContactName5" class="txt"/>
        </div>
        <div class="col-md-3" style="padding-left:0%">

另一个页面名称default_results.php我已创建输入字段

<div class="col-md-5 padding-rht">
    Minimum Buyer Contribution
    </div>
    <div class="col-md-2 padding-Zero"> 
        <input type="text" id="txtCustomerName3"  class="txt"  />
    </div>

我厌倦了 jQuery 脚本

<script>
 $(function () {
        $("#btnQueryString").bind("click", function () {
            var url = "default_results.php?id=" + encodeURIComponent($("#txtLocationContactName5").val()) + "&technology=" + encodeURIComponent($("#txtCustomerName3").val());
            window.location.href = url;
        });
    });
</script

但不起作用,那么如何将一页的值传递到另一页?

最佳答案

你这是在为自己找麻烦!需要一个简单的表单来帮助您将数据传递到另一个页面:)。有关 html 表单的信息,请参阅此处 - http://www.w3schools.com/html/html_forms.asp

这是一个简单的例子:

<form action="page_2_link" method="POST">
   <input type="text" name="field1" value="easy">
   <input type="submit" name="button1" value="Submit">
</form>

然后在第二页上您可以执行以下操作来检索表单数据:

<?php
   $blah = $_POST['field1']; // this now has the posted fields value
?>

我已经用 PHP 给出了第二页答案,因为您已使用它作为这个问题的标签,所以我希望您使用它,否则我的答案将不起作用。

关于javascript - 如何在 JavaScript 中使用查询字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32070601/

相关文章:

javascript - 在 Factory 中设置局部变量作为 Ajax 调用的结果

javascript - 处理JS中的查询字符串,如http_build_query等

javascript - 如何在 Typescript 中打印 iframe 内容

jquery - IE CSS 悬停在 img 上时失去焦点

javascript - 将 jQuery 转换为 Angular 并优化性能

php - 通过 PHP 检测 excel .xlsx 文件 mimetype

PhpStorm 和 PSR-12,如何将其添加为默认编码样式?

php - 使用 git 的 Web 开发工作流程

javascript - 使用foundation.core.js时出错

javascript - 如何在javascript中使用svg文本标签