English 中文(简体)
如何用点击方法添加点击方法?
原标题:How to add a click method inside of element with click method?

附录一

   <div id="outer" onclick="thingsHappen()">
      <div id="inner"></div>
   </div>

当我点击outerinner div时,就处决了 things。 这是显而易见的。

Now I have got a need to define a different method for the inner div. For example

$("#inner").click(function() {
    doThings();
});

When I click on inner both thingsHappen() and doThings() executes. How do I execute doThings() when I click on inner div without executing thingsHappen()?

I tried to unbind click method from #inner, but it did not work. PS. I cannot change the structure of HTML.

最佳回答
问题回答

页: 1

$("#inner").click(function(e) {
    doThings();
    e.stopPropagation();
});

涉及儿童部分的事件,除非传播活动停止,否则会影响到马达加斯加的家长:

$("#inner").click(function(event) {
    doThings();
    event.stopPropagation();
});

http://www.quirksmode.org/js/events_order.html

$("#inner").click(function(e) {
    e.stopPropagation();
    doThings();
});​

你们试图做的是阻止事件(浮标)从“泡沫”上起。 在这种情况下,你想要停止在泡沫阶段宣传这一事件。 如果你使用舱位,你可以利用这一功能:

HTML

<div id="outer" onclick="thingsHappenOuter()"> 
    <div id="inner">
    </div> 
</div>

<>JS

$("#inner").click(function(event) {       
    event.stopPropagation();
    // do something     
});

SEE:, 供参考。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签