我有一个onmousedown
的div,但点击未被识别。没有警报弹出。这是一个带有工作示例的codepen。
http://codepen.io/anon/pen/QbzYpb?editors=110
以下是代码示例。
<ion-header class="bar bar-subheader">
<div class="title">
the cool title
</div>
<div onmousedown="alert(1)" id="filter-button">
<span class="assertive">
<i class="icon ion-arrow-down-b"></i>
CLICK ME
</span>
</div>
</ion-header>
CSS
#filter-button {
width: 100px;
float: right;
height: 54px;
font-size: 20px;
padding-right: 12px;
}
为什么这不起作用,我该如何解决?
答案 0 :(得分:1)
以某种方式浮动此div(#filter-button)会导致它没有收到点击事件,但您可以使用以下css修复它:
#filter-button {
width: 100px;
position: absolute; //changed position to absolute and removed float
height: 54px;
font-size: 20px;
right: 12px; //changed from padding right to positioning 12px from right edge
}
现在它就像一个魅力 - link
答案 1 :(得分:1)
您的.title
元素与过滤器按钮重叠。要使您的过滤器按钮位于.title
元素上方,您需要将z-index: 1
设置为它。
E.g。
#filter-button {
width: 100px;
float: right;
height: 54px;
font-size: 20px;
padding-right: 12px;
position: relative; /* need this for z-index to work */
z-index: 1;
}
答案 2 :(得分:0)
答案 3 :(得分:0)
参见示例..........
<div onmousedown="alert('onmousedown workinkg')" id="add id" class="add class">
Mousedown Test <br/>
Add any code and tag Here....
</div>
&#13;