如何将项列表附加到另一个HTML页面上的文本框值
我有一个页面, choosemerchant
我获得商家列表。 选择列表项后,我想将该列表项值附加到属于不同html页面的文本框id。 这是我的代码:
$('.ui-li-icon li').click(function() { var index = $(this).index(); text = $(this).text(); alert('Index is: ' + index + ' and text is ' + text); sessionStorage.setItem("selectedMerchant", text); window.location="recommendmanual.html"; $('#merchant').append(text); });
在我的包含textbox id=merchant
页面中,我将此代码放在脚本中:
var selectedMerchant = ""; if ( sessionStorage.getItem("selectedMerchant") ) { selectedMerchant = sessionStorage.getItem("selectedMerchant"); }
它以前工作过,但现在它不起作用。
我不知道我是否理解你的问题以及这是否对你有所帮助
但是如果你想通过点击你的selectmerchant页面中的li元素,点击的项目文本会出现在页面上的texarea中推荐手册
这是choosemerchant页面的代码:
这是推荐手册页面的代码
使用此解决方案,如果您单击第一页中的一个li项目文本将出现在第二页textarea中。
如果我没有正确理解你的问题并且这个解决方案不适合你的需求,我为你让你浪费时间而道歉。
这两行中的第二行:
... window.location="recommendmanual.html"; $('#merchant').append(text); ....
将无法访问:浏览器将立即开始加载“recommendedmanual.html”并停止执行当前脚本。
在重定向到其他页面之前,有一件事将文本附加到#merchant,即$('#merchant').append(text);
这应该在window.location="recommendmanual.html";