redirect user to current page with some querystring using javascript

后端 未结 10 2053
無奈伤痛
無奈伤痛 2021-01-01 12:09

When a person clicks on a link, I want to do this:

  1. grab the text from a textbox
  2. encode the text
  3. redirect to currentpage.aspx?search=textboxva
10条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 12:56

     $(document).ready(function(){
         $('a').click(function(e){
    
             window.location = "?search=" + encodeURIComponent($("#someId").val());
    
             //this line of code is intended for older ie and might work,
             //because I don't remember it exactly
            e.stopPropagation();
    
             return false;
         });                                                                   
    

    });

提交回复
热议问题