button causing page to reload

后端 未结 2 775
星月不相逢
星月不相逢 2021-01-26 03:38

I am using html and jquery on my page.

In my html i have one button which when clicked will fire one function.

When page loads i call main function in document r

相关标签:
2条回答
  • 2021-01-26 03:54

    by default BUTTONS are of type SUBMIT, try this instead

    <button type="button" id="btnSearch" onclick="search()" >Search</button>
    
    0 讨论(0)
  • 2021-01-26 04:02

    This is working fine for me. See demo

          $(document).ready(function () {
            main();
    
          });
          function main(){
          		  //some code goes here
          			alert('main');          
          }
    
          function search(){
               //some logic
               alert('search');
          }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div>
      <button id="btnSearch" onclick="search()" >Search</button>
    </div>

    0 讨论(0)
提交回复
热议问题