简体   繁体   English

单击工具提示中的链接时,Tooltipster插件不会触发jquery函数

[英]Tooltipster plugin not firing jquery function when link in in the tooltip is clicked

I am using a jquery plugin called Tooltipster ( http://calebjacob.com/tooltipster/ ) and I am insterting some HTML into the tip which contains an href. 我正在使用一个名为Tooltipster的jquery插件( http://calebjacob.com/tooltipster/ ),我正在将一些HTML包含在包含href的tip中。 If I click the link the page is opened as I expect. 如果我单击链接,页面将按预期打开。 However, if I try to use that same href, add a class name and then try to fire a jquery function it will not fire. 但是,如果我尝试使用相同的href,添加一个类名,然后尝试触发一个jquery函数,它将不会触发。 I have been pulling my hair out for hours trying to figure this out. 我一直把头发拉了几个小时试图解决这个问题。 Any help would be appreciated. 任何帮助,将不胜感激。 Here is some stripped down code to illustrate an example. 这里有一些精简代码来说明一个例子。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<link rel="stylesheet" type="text/css" href="tooltipster.css" />
<script language="javascript" type="text/javascript"  src="Scripts/jquery-1.8.0.min.js"></script>
<script language="javascript" type="text/javascript" src="Scripts/jquery.tooltipster.js"></script>

<script>
$(document).ready(function() {
    $('.element').tooltipster({
       animation: 'fade',
       delay: 180,
       offsetX: 0,
       offsetY: 0,
       onlyOne: true,
       position: 'top',
       maxWidth: '300',
       speed: 150,
       timer: 0,
       theme: '.tooltipster-default',
       interactive: true,
       interactiveTolerance: 350,      
       updateAnimation: true,
       trigger: 'custom',
       interactive: true
    });

    $('.element').tooltipster('update', 'Select an Image from the right hand image list.<a class="update" href="#">Cancel Editing.</a>');
    $('.element').tooltipster('show');

    $('.update').click(function(){
        alert("hello");
    }); 

});


</script>

</head>

<body>

<a class="update" href="#">Hello</a>


<div align="center" class="element" title="Try clicking <a href='http://google.com'>this link</a>"> 
    <p>This div has a tooltip when you hover over it!</p>
</div>

</body>
</html>

I put together a Fiddle to illustrate the issue. 我把小提琴放在一起来说明这个问题。 http://jsfiddle.net/bCqyL/ http://jsfiddle.net/bCqyL/

When you set click handler for .udpate element, jquery has not known about elements with this class yet. 当你为.udpate元素设置click handler时,jquery还不知道有关这个类的元素。 This is why handler does not set in you example. 这就是处理程序没有在您的示例中设置的原因。 Instead please use an other approach, that handles all clicks for the document and selects only addressed for .update elements. 相反,请使用另一种方法,处理文档的所有点击,并仅选择针对.update元素的地址。

$(function(){
    $(document).on('click', '.update', function(){
        alert('hello');
        return false;
    });    
});

http://jsfiddle.net/bCqyL/3/ http://jsfiddle.net/bCqyL/3/

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

相关问题 当按钮或任何点击发生时,Tooltipster插件不会触发jquery功能 - Tooltipster plugin not firing jquery function when button or any click even occur JQuery Tooltipster插件不会在html内容中显示带有超链接的工具提示 - JQuery Tooltipster plugin does not show the tooltip with a hyperlink in the html content jquery tooltipster插件无法正常工作 - jquery tooltipster plugin not working JQuery-Plugin-Tooltipster:如果带有工具提示的元素带有其他工具提示的子元素,则“ onlyOne”不起作用 - JQuery-Plugin-Tooltipster: “onlyOne” does not work if an Element with tooltip got child with additional tooltip 工具提示有效。 现在:TypeError:$(&#39;。tooltip&#39;)。tooltipster不是函数 - Tooltipster worked. Now : TypeError: $('.tooltip').tooltipster is not a function jQuery click()函数无法识别单击链接时 - Jquery click() function not recognising when a link is clicked 使用WordPress时工具提示工具提示内容为空 - Tooltipster tooltip contents empty when using WordPress jQuery Validation Plugin和Tooltipster Plugin错误 - jQuery Validation Plugin and Tooltipster Plugin error Tooltipster jQuery插件,用于检查空文本框 - Tooltipster jQuery plugin to use for checking empty textbox 关于使用 jquery tooltipster 插件的问题 - Question about using jquery tooltipster plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM