jquery - 使用 qtip 到多个地方但内容不同?

标签 jquery html css qtip

嗨,

我正在使用qTip在我的网站上,文档就绪功能如下所示:

    $.fn.qtip.styles.mystyle = { // Last part is the name of the style
       width: 200,
       background: '#ebf1ff',
       color: 'black',
       textAlign: 'center',
       border: {
          width: 1,
          radius: 4,
          color: '#AACCEE'
       },
       tip: 'bottomLeft',
       name: 'dark'
    }



   $('.controlTitleContainer .icon').qtip({
       content: $(this).find('.tooltip').html(),
        position: {
              corner: {
                 target: 'topRight',
                 tooltip: 'bottomLeft'
              }
           },
       style: 'mystyle'
    });

第一部分仅用于样式,但第二部分将填充 qtip。

我的 HTML 看起来像这样:

 <div class="controlTitleContainer">
      <div class="text">
           <label for="ModelViewAd_Title">Titel</label>
      </div>
      <div class="icon">
           &nbsp;<div class="toolTip">MyToolTipTest</div>
      </div>
  </div>

注意:类 toolTip 设置为 Display : none,并且 class="icon"div 将显示工具提示

我会在页面上有很多这样的 html 片段,但它将包含不同的数据,我需要的是工具提示来显示 .这是可能的还是我必须为每个这样的 HTML 片段生成 qtip 声明?

请多多指教

致以诚挚的问候

最佳答案

为什么不这样呢?

$(document).ready(function(){
    $.each($(".tooltip"), function(i,val){
        $.fn.qtip.styles.mystyle = { 
           width: 50,
           background: '#ebf1ff',
           color: 'black',
           textAlign: 'center',
           border: {
              width: 1,
              radius: 4,
              color: '#AACCEE'
           },
           tip: 'bottomLeft',
           name: 'dark'
        }

        var theContent = $(val).html();
        $(val).qtip({
            content: theContent,
             position: {
                      corner: {
                         target: 'topRight',
                         tooltip: 'bottomLeft'
                      }
                   },
               style: 'mystyle'
        });
    });
});

这样,任何具有 class="tooltip"div 都会自动启用 qTip。这实际上就是我在我的元素中所做的。

这是我的测试 HTML:-

 <div class="controlTitleContainer">
      <div class="text">
           <label for="ModelViewAd_Title">Titel</label>
      </div>
      <div class="icon">
           &nbsp;<span class="tooltip">MyToolTipTest</span>
           &nbsp;<span class="tooltip">MyToolTipTest2</span>
           &nbsp;<span class="tooltip">MyToolTipTest3</span>
      </div>
  </div>

关于jquery - 使用 qtip 到多个地方但内容不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4961525/

相关文章:

javascript - 使用 jquery 多次追加 div

html - Div 高度 100% 不适合 bootstrap 和 wordpress

css - 为什么我的 CSS 不能在 GitHub Pages 上运行?

jQuery 手机 : Numbers only input field?

html - HTML 属性值中的引号?

html - Bootstrap + CSS : Constrain table height in modal

html - 根据内容大小将 HTML 分成页面

javascript - 当我将鼠标悬停在动态创建的行上时,该行中的选择元素(标签)选项没有正确下拉。火狐问题?

javascript - 在 URL 中使用井号获取 window.location.pathname - javascript

javascript - 一个接一个地改变不同跨度的颜色