如何将Jquery的值传递到其他页面? [英] how do I pass Jquery value to a different page?

查看:114
本文介绍了如何将Jquery的值传递到其他页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在新页面加载后将输入值传递给另一个页面.仅HTML和jQuery可以做到吗?

I'm trying to pass an input value to a different page after the new page loads. Is this possible with just HTML and jQuery?

这是我的代码:

<input id='search' type="text" size="100"/>
<button id='search-button'><p>G</p><img src='img/search.png' alt="GO"/></button>
<h1 class="show-result">Results for</h1>



//Jquery//
 $('#search-button').click(function() {

var search = $('#search').val();

  window.location.href = 'result.html';

$('.show-result').append( ' "' + search + '"');
return false;
});

推荐答案

您的第一页将显示如下内容:

Your first page would read something like :

$('#search-button').click(function() {
    var search = $('#search').val();
    window.location.href = 'result.html?search=' + search; //This line is edited
    $('.show-result').append( ' "' + search + '"');
    return false;
});

您的第二页可能显示如下内容:

Your second page could read something like:

function getUrlVars() { // create a cool little function
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
    vars[key] = value;
});
return vars;
}

var search = getUrlVars()["search"]; //use that function
alert(search); //this is just one way to show the GET parameter

信用属于此处: http://papermashup.com/read-url-get -variables-withjavascript/

这篇关于如何将Jquery的值传递到其他页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆