Jquery plugins 带有事件链接的jquery循环标题

Jquery plugins 带有事件链接的jquery循环标题,jquery-plugins,jquery,jquery-cycle,Jquery Plugins,Jquery,Jquery Cycle,我正在使用jquery循环,它运行正常,只有jquery事件不起作用 我基本上用标题循环图像,我在“alt”属性中设置标题 在特定的图像上,我调用一个模态,为图像指定一个类,并让jquery生成一个模态——这很好 我还在标题中添加了一个链接,我可以在那里看到链接,但是当我点击链接时,jquery不会被触发 这是一张带有此标题和链接的图像 <img class="openModal" src="images/video.jpg" alt="<div class='wrap'>&l

我正在使用jquery循环,它运行正常,只有jquery事件不起作用

我基本上用标题循环图像,我在“alt”属性中设置标题

在特定的图像上,我调用一个模态,为图像指定一个类,并让jquery生成一个模态——这很好

我还在标题中添加了一个链接,我可以在那里看到链接,但是当我点击链接时,jquery不会被触发

这是一张带有此标题和链接的图像

<img class="openModal" src="images/video.jpg" alt="<div class='wrap'><h1 class='caption-title'>Video</h1><p class='caption-desc'>Aliquam lectus orc ac.<a class='button' class='openModal'>watch the video</a></p></div>"/>
循环运行良好

我点击图像,打开模态-完美

我点击标题中的这个链接,它什么都不做


我在这里遗漏了什么?

这可能是因为您在将HTML插入页面之前绑定了事件

试试这个:

$('.cycleOrCaptionContainer').on('click', '.openModal', function(e) {
    console.log('this is the click');
    e.preventDefault();
});

'.CycleOrcationContainer'
将侦听来自类为
.openModal
的子元素的
'click'
,即使在代码运行后附加此元素。

为什么要在
alt
属性中添加HTML片段?它仅用于文本。你希望它做什么?那么你想打开一个模式点击标题吗?最初的想法是简单地列出一个标题,然后它需要样式,然后添加一个链接。我想通过点击标题中的链接打开一个模式。
   $('.openModal').on('click', function (e) {
    console.log('this is the click');
    e.preventDefault();
});
$('.cycleOrCaptionContainer').on('click', '.openModal', function(e) {
    console.log('this is the click');
    e.preventDefault();
});