Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery上的事件?_Jquery_Events - Fatal编程技术网

jquery上的事件?

jquery上的事件?,jquery,events,Jquery,Events,当我单击element.conversation\u item>span jquery时,conversation\u item和conversation\u item>span都处于活动状态。我不想要它,但我必须在事件中使用。帮助我。您需要在单击事件时使用 $('body').on('click', '.conversation_item', function (e) { e.preventDefault(); console.log("go"); }); $('body')

当我单击element.conversation\u item>span jquery时,conversation\u itemconversation\u item>span都处于活动状态。我不想要它,但我必须在事件中使用。帮助我。

您需要在单击事件时使用

$('body').on('click', '.conversation_item', function (e) {
    e.preventDefault();
    console.log("go");

});
$('body').on('click', '.conversation_item > span', function () {
    console.log("true");
});

您需要停止以单击子元素:

$('body').on('click', '.conversation_item > span', function (e) {
 e.stopPropagation()
  alert("true");
});

您应该停止事件传播。看看这个


@skd很高兴帮助您:)
$('body').on('click', '.conversation_item > span', function (event) {
   event.stopPropagation();
   console.log("true");
});