父单击事件未按预期运行
Parent click event not running as expected
在我的页面设计中有以下div层次结构。我在bill-item元素上绑定了一个click事件,该元素有多个覆盖bill-item元素的子元素。
<div class="bill-item">
<!-- Item image -->
<div class="bill-item-img"></div>
<!-- Item description -->
<div class="bill-item-description">
<div class="bill-item-name">
<!-- Item Name -->
<p class="bill-item-name-left">Normal Cofee</p>
<!-- Item Price -->
<p class="bill-item-name-right">170.00</p>
<div class="clear"></div>
</div>
<!-- Total item price -->
<div class="bill-item-price"> <span>170.00</span>
</div>
<!-- Item Quantity -->
<div class="bill-item-amount"> <span>1</span>
</div>
</div>
<!-- Increas & Decrease item Quantity -->
<div class="bill-amount-selection"> <a class="amount-increase" href="#"></a>
<a class="amount-decrease" href="#"></a>
</div>
<div class="kot-bot"> <span>-- KOT / BOT --</span>
</div>
</div>
但是当我点击bill-item元素时,点击事件没有被执行!有人能告诉我怎么才能触发事件吗。这是我绑定click事件的方法。
$('.bill-item-list').on('click', '.bill-item', function(e) {
var posX = e.pageX;
var posY = e.pageY;
showToolTip(posX,posY,this);
})
在代码片段中没有看到bill-item-list元素。试试以下命令:
$('.bill-item').click(function(e) {
var posX = e.pageX;
var posY = e.pageY;
showToolTip(posX, posY, this);
});
如果bill-item-list是所有bill-item的实际父项,那么你的方法应该有效:
$('.bill-item-list').on('click', '.bill-item', function(e) {
var posX = e.pageX;
var posY = e.pageY;
showToolTip(posX, posY, this);
});
相关文章:
- 单击按钮前运行事件
- 单击链接时停止运行javascript
- 在单击事件中,第一次单击时激发代码一次,其余代码在所有单击时运行
- 在Node Webkit应用程序中从DOM单击按钮时运行批处理文件
- 计时器自动运行,而不是单击javascript按钮
- 运行“;非“;单击另一个函数中的函数仅一次
- 单击1个表单中的2个提交按钮中的1个时,如何运行脚本
- 在同一页面上单击按钮运行不同的代码
- 附加 jQuery 代码以在加载和按钮单击时运行
- 我需要在单击时运行两个函数.即使嵌套在一起,我也无法让它们都工作
- 如何制作按钮.单击“开始时不运行”
- 如何加载一个html页面并在其中只需单击一次即可运行函数
- 每次用户单击按钮时运行if语句检查器
- 运行Javascript更改RadioButtonList单击时的值
- 第二次单击时,使用JQUERY运行另一个函数
- 使用运行时创建的链接来触发ASP.Net中隐藏按钮的单击处理程序
- 我的 update.js.erb 文件仅在第一次单击按钮时运行,而不在后续单击时运行(单击时更改按钮的类和值)
- 如何在元素的默认行为之后运行单击功能
- 焦点在单击/更改单选按钮之前运行.是否可以在焦点之前运行单击/更改
- 当我单击dblclick时,它会运行.单击两次