简体   繁体   English

页面加载后更改cluetip内容

[英]Changing cluetip content after page load

I want to change cluetip content after the page is loaded. 我想在页面加载后更改cluetip内容。

Let's say I have a button in my cluetip and after clicking it, I want it gone. 假设我的cluetip中有一个按钮,点击它后,我希望它消失了。

So here's the cluetip: 所以这是cluetip:

 $('a.notice_tooltip').cluetip({activation: 'click', cluetipClass: 'jtip' ,
 local:true ,   positionBy: 'bottomTop' , arrows: true,   sticky: true  ,   closePosition: 'title' });

HTML: HTML:

    <a class="notice_tooltip" href="#" rel="#info_div"  > open tooltip </a>
    <div id="info_div"> 
    <input class="btn' type="button" >
    <input class="btn2' type="button" >
    </div>

Here is the click event: 这是点击事件:

$('.btn').click(function(){
  //do stuff

  $(this).parent().append(some_message);
  $(this).remove();

})

$('.btn2').click(function(){
  //do stuff

  $(this).parent().append(some_message);
  $(this).remove();

})

This would remove the button and append a message to it's parent but when I reopen the cluetip, it's the old content again. 这将删除按钮并向其父级添加消息,但是当我重新打开cluetip时,它又是旧内容。

It's like, the plugin gets the DOM structure when the page is loading and after that, it doesn't care about the page changes. 就像,插件在页面加载时获取DOM结构,之后,它不关心页面更改。

I've tried to run the plugin again every time it gets closed. 我每次关闭时都试图再次运行该插件。

 $(function(){

    $('.btn').click(function(){
      //do stuff
      $(this).remove();

    })

        $('a.notice_tooltip').cluetip({activation: 'click', cluetipClass: 'jtip' , local:true ,   positionBy: 'bottomTop' , 
        arrows: true,   sticky: true  ,   closePosition: 'title' , onHide : function(ct,c) {

          retooltip();

          }

        });
 })

     function  retooltip(){
       $('a.notice_tooltip').cluetip('destroy');
       $('a.notice_tooltip').cluetip({activation: 'click', cluetipClass: 'jtip' , local:true ,
         positionBy: 'bottomTop' , arrows: true,   sticky: true  ,   closePosition: 'title' , onHide : function(ct,c) {
           retooltip();

         }

       });
      }

It's still the same. 它仍然是一样的。

The problem 问题

Each time Cluetip is closed, it throws its content away, and retrieves it from the original element next time it's opened. 每次Cluetip关闭时,它都会抛弃其内容,并在下次打开时从原始元素中检索它。 This means that if you want to make persistent modifications to the content of a Cluetip, you have to also make those modifications to the original element. 这意味着如果要对Cluetip的内容进行持久修改,则还必须对原始元素进行修改。

A possible solution 可能的解决方案

When your button is clicked, look up until you find the cluetip inner wrapper, and select its first child div . 单击按钮后,查找直到找到cluetip内部包装器,并选择其第一个子div Use this to find the original div , and remove the button inside that. 使用它来查找原始div ,并删除其中的按钮。 Then remove the clicked button. 然后删除单击的按钮。

$(function(){
    $('a.notice_tooltip').cluetip({
        activation: 'click', 
        cluetipClass: 'jtip',  
        local: true,
        positionBy: 'bottomTop', 
        arrows: true,   
        sticky: true  ,
        closePosition: 'title'
    });

    $('.btn').click(function(){
        // Find the original element
        var originalId = $(this).closest('.cluetip-inner > div').attr('id');            
        // Remove it
        $('#' + originalId).find('.' + $(this).attr('class')).remove();
        // Remove the clicked button
        $(this).remove();
    });

});​

Working example . 工作实例

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

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