问题描述:
今天在制作table表单统计功能时,点击button按钮时发现在执行js统计函数后页面自动刷新,使得做的结果出不来。
问题原因:
在使用标签时 submit会默认提交数据,重新加载页面。(ps:如果没用到type属性可能也会有一样的问题)
解决方法:
把type=“submit”改为type=“button”或者直接加上type=“button”。
图片:
html页面
<button class="col-sm-3 btn btn-w-m btn-info" type="button" href="javascript:void();" onclick="count()" >分数统计:</button>
<div class="col-sm-6">
<input id="score1" name="score" class="form-control" type="text">
</div>
ps:如果有对我这个统计功能有兴趣的可以在评论@我