How to add a certain value to anchor tag?

后端 未结 5 1151
时光说笑
时光说笑 2020-12-31 07:26

I have the following code

Inside Link which sets a value



        
5条回答
  •  时光说笑
    2020-12-31 08:15

    data-value is a good attribute. but.. You can also add a " rel " attribute to your anchor tag. it describes the relation to the document where the link points to. And you can also use it to store a value.

    Like This -

    $("a").click(function(){
     var page = $(this).attr('rel'); // save the attribute value here
    
     sessionStorage.setItem("text",page);
    
    /*save it in session storage if you want to send (or retrieve) this value to another page. 
    if not then use it easily without saving it in session storage*/
    
     //Use it here 
    
     return false; // to stop the redirection if  contains a link
    });
    
    

提交回复
热议问题