简体   繁体   中英

Make a transition text without href

I have a div containing a group of divs.

I want the divs inside to work as links that move to another page after saving this link's value.

The div consists of the id in the div attribute, & the name in the div's value as follows:

Html:

    <div id="ClasssesList" ></div> 

jQuery:

function GetClassesList(data) {
   var classes = (typeof data) == 'string' ? eval('(' + data + ')') : data;
   $('#ClasssesList').empty();
   for (var i = 0; i < classes.length; i++) {
      var text = '<button class="BigDiv" value="' + classes[i].Cls_ID + '" >' + classes[i].Cls_Name + '</button>';
    $('#ClasssesList').append(text);
   }
}

I want to save the value of the clicked id in a localStorage then move to the next page:

I tried to make it as follows, but it doesn't seem to be working:

$("#ClasssesList").bind('click', 'button.BigDiv',CallLink()); 

function CallLink(e) {

        localStorage['ClassID'] = $('Button.BigDiv').attr('value');
        window.location.replace("Teacher_Attendance.htm");
 }

Do you know what should I do to let it work ?

function CallLink(e) {

        localStorage.setItem('ClassID', $('Button.BigDiv').attr('value'));

        window.location.replace("Teacher_Attendance.htm");
 }

And to get that item try:

localStorage.getItem('classID');

Format to set data to localStorage is

localStorage.setItem(key, value);

here value is string format;

you will get more here Microsoft , Mozilla and Apple .

And one note

I think your bind function

$("#ClasssesList").bind('click', 'button.BigDiv',CallLink())

should be written as

$("#ClasssesList").on('click', 'button.BigDiv',CallLink())

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