redirect user to current page with some querystring using javascript

后端 未结 10 2028
無奈伤痛
無奈伤痛 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:51

    You are changing the wrong location property if you only want to change the search string. I think you want to do this:

    location.search = "?search=" + encodeURIComponent( $("#someId").val());
    

提交回复
热议问题