有画布标签。我在菜单上有菜单和子菜单。当用户点击Setting
时,显示子菜单。子菜单显示在画布上,但如果我点击子菜单调用画布点击事件。
<div id="canvas">
<ul class="toolBarul" id="toolBar">
<li class="toolBarli">
<a class="button" onclick="toggleSetting()">Setting</a>
<ul id="SettingWrap">
<li><input id="rainControl" type="checkbox" onchange="rainControl(this)"><label>rain<span class="chktoc"></span></label></li>
<li><input id="flameControl" type="checkbox" onchange="flameControl(this)" checked="checked"><label>flame<span class="chktoc"></span></label></li>
</ul>
</li>
<li class="toolBarli" style="float: right;padding: 4px;">
<img src="images/Logo.png" />
</li>
</ul>
</div>
#SettingWrap{
display:none;
width: 280px;
height:308px;
top: 100%;
position: absolute;
z-index: 598;
list-style: none;
margin: 0;
padding: 0;
background: rgba(0, 40, 58, 0.91);
padding: 5px;
}
#SettingWrap li {
width: 267px;
height: 40px;
line-height: 40px;
vertical-align: middle;
padding: 5px 10px;
color: #9dd702;
}
根据this article,我写下面的代码,但不起作用:
$("#SettingWrap").on("mousedown", function (e) {
e.preventDefault();
});
答案 0 :(得分:0)
正如@Mosh Feu在评论中所说,我在画布的event.stopPropagation()
事件之前叫click
,它解决了我的问题。