怎么样才能点击h1标签的123456 不弹出"p"
<p style="border:1px solid red;width:100px;height:100px;" onclick="alert('p')">
<h1 onclick="alert(123456)">
123456
<h1>
</p>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这其实是个js冒泡。现在你要做的是阻止冒泡事件。
这没办法吧,你把函数写在html里面了,你要是写在 script 里面的话,可以在 h1 绑定的那个函数里面最后加 e.preventDefault(), (e是传入函数的一个事件对象),或者 加 return false。