JavaScript onclick redirect

前端 未结 5 1811
礼貌的吻别
礼貌的吻别 2021-02-04 18:40

I have this text field and button here

            


        
5条回答
  •  悲&欢浪女
    2021-02-04 19:22

    There are several issues in your code :

    • You are handling the click event of a submit button, whose default behavior is to post a request to the server and reload the page. You have to inhibit this behavior by returning false from your handler:

      onclick="SubmitFrm(); return false;"
      
    • value cannot be called because it is a property, not a method:

      var Searchtxt = document.getElementById("txtSearch").value;
      
    • The search query you are sending in the query string has to be encoded:

      window.location = "http://www.mysite.com/search/?Query="
          + encodeURIComponent(Searchtxt);
      

提交回复
热议问题