如何在javascript中的不同html页面之间传递变量值 [英] How to pass variable value between different html pages in javascript

查看:321
本文介绍了如何在javascript中的不同html页面之间传递变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所选列表项的值传递给另一个页面,这意味着如果我从列表中选择abc,则此abc值将传递到下一个html表单,并且应该打开该配置文件

  $('。ui-li-page only.Is有任何方法可以在不同的html页面中使用这个变量。图标li')。click(function(){
var index = $(this).index();
text = $(this).text();
alert('Index是:'+ index +',文本是'+ text';

我想通过上述文本值到我的 profile.html 这是具有javascript功能 profile()。所以我想通过这个文本函数调用像配置文件(文本);我试着声明var文本在函数调用之上,但仍然不起作用。请告诉我是否有其他方式。

值作为url片段。



在您的点击功能中,打开'/ pr ofile.html#'+ text



在您的profile.html中获取url片段。



示例代码:



导航至profile.html

  window.location.href ='< profile.html的路径>'+'#'+ text; 

在profile()中,要获取参数,请使用

  var text = window.location.hash.substring(1)


I want to pass the value of selected list item to the other page,means if I m selecting abc from the list then this abc value passes to the next html form and it should open that profile page only.Is there any way that I can use this variable among different html page.

$('.ui-li-icon li').click(function() {
    var index = $(this).index();
    text = $(this).text();
    alert('Index is: ' + index + ' and text is ' + text);

I want to pass the above text value to my profile.html which is having javascript function profile().So I want to pass this text in function call like profile(text);I tried declaring var text above the function call but still its not working.Pls tell me if any other way is there.

解决方案

You can pass the value as a url fragment.

In your on click function, open '/profile.html#'+text

In your profile.html get the url fragment.

Sample code:

To navigate to profile.html

window.location.href = '<path to profile.html>' + '#' + text;

In profile(), to get the parameter, use

var text = window.location.hash.substring(1)

这篇关于如何在javascript中的不同html页面之间传递变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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