如何将查询字符串中的 javascript 变量从一个 html 页面传递到另一个页面

发布于 2024-09-19 19:31:32 字数 609 浏览 2 评论 0原文

我有两个 html 页面 example1.html 和 example2.html ,如何在查询字符串中将 javascript 变量用户名从 example1.html 传递到 example2.html 。

<script type="text/javascript" >
    $(document).ready(function() {
        $('#SubmitForm').submit(function() {
            var username = ($("#username").val());
               ...........
                ..........
              ..............
               .........

</script>
<body>
<div id="example2"><a href="http://localhost:1894/blockseek8-9-2010/example2.html?Var1=username" class="MainNav"></a></div>
</body>

I have two html pages example1.html and example2.html ,how can i pass a javascript variable username from example1.html to example2.html in querystring.

<script type="text/javascript" >
    $(document).ready(function() {
        $('#SubmitForm').submit(function() {
            var username = ($("#username").val());
               ...........
                ..........
              ..............
               .........

</script>
<body>
<div id="example2"><a href="http://localhost:1894/blockseek8-9-2010/example2.html?Var1=username" class="MainNav"></a></div>
</body>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜是你 2024-09-26 19:31:32

您可以修改链接的 href 属性:

$("#example2 a").attr("href", url + "?var1=" + username);

如果用户名使用特殊字符,您将需要对其进行 url 编码。

You can modify the href attribute of your link:

$("#example2 a").attr("href", url + "?var1=" + username);

If username uses special characters you will need to url encode it.

嗼ふ静 2024-09-26 19:31:32

您可以使用 PHP,或设置 location.search

You could either use PHP, or set location.search.

罗罗贝儿 2024-09-26 19:31:32

使用 cookies 怎么样? http://plugins.jquery.com/project/Cookie - 无需修改查询字符串:)

What about using cookies? http://plugins.jquery.com/project/Cookie - no need to modify query string :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文