硬汉工作室

搜索
热搜: 活动 交友 discuz

html里点击button为什么会提交表单?

[复制链接]
发表于 2022-1-7 11:43:11 | 显示全部楼层 |阅读模式
页面里经常需要用到按钮,用<button>的时候发现,点击它会自动提交表单,不知道为啥,因为我提交表单一般都是用<input type= "submit">的,百度了下,原来button的type属性默认是submit,也就是提交功能,如果想用它当作普通按钮,需要指定type="button",也就是:<button type = "button">clickme</button>

刚才用js测试了下,发现button的type属性默认确实是submit。
<form>
    <button id = "btn">hello</button>
</form>
<script>
    function foo() {
        var o = document.getElementById('btn');
        console.log(o.type);
        return false;
    }
</script>

有关PHP系统、Discuz或网站等各种问题,可以联系QQ1069971363寻求付费支持
Discuz插件商店:http://addon.dismall.com/?@56030.developer
回复

使用道具 举报

QQ|Archiver|手机版|小黑屋|硬汉工作室 ( 冀ICP备13021567号-9 )

GMT+8, 2024-4-26 09:26 , Processed in 0.056040 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表