redirect user to current page with some querystring using javascript

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

    The problem with appending something to window.location.href is what if you have already done that? You'll just keep appending "?search=..." multiple times. More importantly, it's more complicated than it needs to be.

    You're already using jQuery. Why not just do this?

    
    Search
    

    with:

    $(function() {
      $("#go").click(function() {
        $("#search").submit();
        return false;
      });
    });
    

    and then you don't have to worry about the right URL, encoding, etc.

提交回复
热议问题