2012-07-05 74 views
0

我正在編寫一個JavaScript應用程序,並且我找到了一個不錯的庫qtip2。我的目標是當用戶將鼠標懸停在表格中的每個單元格上時,會顯示不同的信息。我上面提到的那個庫可以在一個小的彈出窗口中顯示信息。但是,我不確定如何在其他設置中使用此功能來將鼠標懸停在其上時顯示每個單元格的特定內容。有人有一個想法,我怎麼能做到這一點?當鼠標懸停在表格單元格上時彈出窗口javascript javascript

function showInfo() 
    { 
      $('#demo-mouse').qtip({ 
       content : 'I position myself at the current mouse position', 
       position : { 
        my : 'top left', 
        target : 'mouse', 
        viewport : $(window),  //keep it on-screen at all time if possible 
        adjust : { 
         x : 10, y : 10 
        } 
       }, 
       hide : { 
        fixed : true    // Helps to prevent the tooltip from hiding occassionaly when tracking! 
       }, 
       style : 'ui-tooltip-shadow' 
     }); 
    } 

回答

1

你可以在你想要顯示的提示要素使用推廣的content性質和用途類:

$('.selector').qtip({ 
    content: { 
     text: function(api) { 
      // Retrieve content from custom attribute of the $('.selector') elements. 
      return $(this).attr('data-tip'); 
     } 
    } 
}); 
+0

非常感謝你的回答。在我給你答案之前最後一件事。我怎樣才能修改我的'​​'在其他方面有你提到的'.selector'? – cybertextron 2012-07-05 23:19:23

+0

只需爲每個''td class =「selectorOrAnythingYouWant」>添加一個'class'屬性,或者添加一個類或者id到表中並且改變這個代碼中的選擇符以匹配:'

'和'$(「#MyTable td」)'。 – rcdmk2012-07-05 23:29:17

+0

我確實進行了您建議的更改,但它們無效。 '

' '' – cybertextron2012-07-05 23:41:27

相關問題
1 1