简体   繁体   English

特定按钮单击

[英]Specific Button Click

I got a quick question: 我有一个简单的问题:

I want every link in the div to alert a message, but only the anchors. 我希望div中的每个链接都提醒消息,但只有锚点。 I dont want the div to initiate the alert function. 我不希望div启动警报功能。

Html: HTML:

<div id="abc">
  <a href='#'> Button 1 </a>
  <a href='#'> Button 2</a>
</div>

Javascript: 使用Javascript:

$(document).ready(function(){
            $('#abc').click(function(){
                alert('a');
            });
        });

How do I modify the above code? 如何修改上述代码?

Then you could just bind the event handler on the a tag inside the div. 然后你可以在div内的一个标签上绑定事件处理程序。

$('#abc a').click(function() {
  alert('a');
});

交换$('#shortlisting')$('#shortlisting a')应该为你工作。

$('#abc a').on("click", function() {
  alert('a');
});

Try: 尝试:

$('#abc a').click(function() {
    alert( $(this).text() );
});

Here is an example 这是一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM