0
点赞
收藏
分享

微信扫一扫

html阻止a标签的跳转,去除form中的button默认事件

左手梦圆 2022-01-31 阅读 102

1.a标签

<a href="JavaScript:;">click me</a>

2.form button

<form id="post-form" method="post" action="/post">
<li class="post-btn">

<button type="submit" id="post-btn">Post<button>

</li>
</form>
let text = $("#post-text");
document.getElementById("post-btn").addEventListener("click", function(event){
//阻止事件
event.preventDefault()
$.post("/post",{"post_text":text.val()},function (data) {
alert(data.msg);
window.location.href="/page/index";
})
});
举报

相关推荐

0 条评论