简体   繁体   中英

Can I store entire label to sessionStorage

Hi all I would like to access label and set the text for that label in another form, so I tried as follows

function ShowNewPage() {
        sessionStorage.setItem("total", $('#<%= lblHidden %>'));
        modalWin.ShowURL('test.html', 300, 400, 'Second From', null, callbackFunctionArray);
    }

But I am not able to access the label it in another form when I use the following sessionStorage.getItem("total") so can some one help me

Web storage only stores strings so you can't store a jQuery object or dom element directly

Just store the selector that references that object and you can wrap the stored selector in $() when you need to use it

sessionStorage.setItem("total", '#<%= lblHidden %>');

Then to use:

var selector = sessionStorage.getItem("total");
alert($(selector).attr('id'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM