如何将项目列表附加到另一个HTML页面上的文本框值 [英] How to Append a List of Items to a Textbox Value on Another HTML Page
问题描述
我有一个页面, choosemerchant
,我在那里获得商家名单。选择一个列表项后,我想将该列表项值附加到属于不同html页面的文本框ID。这是我的代码:
I'm having one page, choosemerchant
where I get the list of merchants. After selecting a list item I want to append that list item value to the textbox id which belongs to a different html page. Here is my code:
$('.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);
});
并且在包含文本框 id = merchant $ c $的页面中c>我把这段代码放在脚本中:
And in my page which contains textbox id=merchant
I have put this code in script:
var selectedMerchant = "";
if ( sessionStorage.getItem("selectedMerchant") ) {
selectedMerchant = sessionStorage.getItem("selectedMerchant");
}
以前有效,但现在无法使用。
It worked before, but now it's not working.
推荐答案
这两行中的第二行:
the second of these two lines:
...
window.location="recommendmanual.html";
$('#merchant').append(text);
....
不会被触及:浏览器会立即开始加载recommendmanual .html并停止执行当前脚本。
will not be reached: the browser will immediately start loading "recommendmanual.html" and stop executing the current script.
这篇关于如何将项目列表附加到另一个HTML页面上的文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!