作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想将选定的列表项的值传递到另一个页面,这意味着如果我从列表中选择 abc,那么这个 abc 值将传递到下一个 html 表单,它应该打开该配置文件仅页面。有什么方法可以在不同的 html 页面中使用此变量。
$('.ui-li-icon li').click(function() {
var index = $(this).index();
text = $(this).text();
alert('Index is: ' + index + ' and text is ' + text);
我想将上面的文本值传递给我的 profile.html,它具有 javascript 函数 profile()。所以我想在函数调用中传递此文本,例如profile(text);我尝试在函数调用上方声明 var text 但仍然无法正常工作。请告诉我是否有其他方法。
最佳答案
您可以将值作为 url 片段传递。
在点击功能中,打开 '/profile.html#'+text
在您的 profile.html 中获取 url 片段。
示例代码:
导航到 profile.html
window.location.href = '<path to profile.html>' + '#' + text;
在profile()中,要获取参数,使用
var text = window.location.hash.substring(1)
关于javascript - 如何在javascript中的不同html页面之间传递变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23213788/
我是一名优秀的程序员,十分优秀!