解决Button按钮点击后自动刷新页面的问题

一、问题

页面上有这样一个按钮,每次点击这个按钮的时候,执行完button的click事件后,会自动的重新刷新一下当前的页面。

 <button class="btn btn-default active" id="btnAdd" style="margin-left:40px;">@GlobalResources.New</button>
 <button id="btnSearch" type="button" class="btn btn-default active" style="margin-left:20px;">@GlobalResources.Search</button>
                              

二、原因
button,input type=button按钮在IE和w3c,firefox浏览器区别: 
1、当在IE浏览器下面时,button标签按钮,input标签type属性为button的按钮是一样的功能,不会对表单进行任何操作。 
2、但是在W3C浏览器,如Firefox下就需要注意了,button标签按钮会提交表单,而input标签type属性为button不会对表单进行任何操作。

三、解决办法
为button按钮增加一个type=”button”属性。

 <button type="button" class="btn btn-default active" id="btnAdd" style="margin-left:40px;">@GlobalResources.New</button>
 <button type="button" id="btnSearch" type="button" class="btn btn-default active" style="margin-left:20px;">@GlobalResources.Search</button>

 

posted @ 2019-12-19 17:23  赵孟蒙  Views(3085)  Comments(0Edit  收藏  举报