2012-07-03 23 views
3

所以我有這個酥料餅這是工作好,這裏是酥料餅的HTML:如何將inline-javascript移動到腳本標記?

<div class="popover2" onmouseover="$(this).mouseleave(function() {$(this).hide(); });"> 
    <div class="arrow"></div> 
    <div class="popover2-inner"> 
     <span class="popover2-title">Popover() 2</span> 
    <div class="popover2-content"> 
     <ul class="unstyled"> 
      <li><span>$200 Bronze</span><p>2 hrs. drivers training</p </li> 
     </ul> 
    </div> 
</div> 

而且我得到這個實例代碼:

$('.popover2-test').popover({ 
    placement:'bottom', 
    template: $('.popover2'), 
    trigger: 'manual', 
    animate: false, 
    html: true, 

     }).click(function(e) { 
      e.preventDefault() ; 
     }).mouseenter(function(e) { 
      $(this).popover('show'); 
    }); 

但我想將內嵌的onmouseover javascript東西移動到實例化代碼中。我不知道該怎麼做。任何幫助都很好,謝謝。

+0

給標籤中的ID,然後只需在綁定JS事件。除非那是該類的唯一標籤,在這種情況下,您可以簡單地使用該類。 – TheZ

+0

你必須更具體,我不知道你在說什麼,對不起,謝謝! – dezman

回答

4

您是否嘗試過在實例化代碼之後放置這行代碼?

$('.popover2').mouseleave(function() { $(this).hide(); }); 
2

只是刪除內聯並添加:

$('.popover2').mouseleave(function(){ 
    $(this).hide(); 
}); 
2

沒有意義,只有結合MouseLeave事件的onmouseover,因爲鼠標懸停事件必須鼠標離開前無論如何火(據我所知)。因此,這會做:

$('.popover2').mouseleave(function() { 
    $(this).hide(); 
}); 

這是假設,當然,這.popover2當你的「實例代碼」運行存在。

如果沒有,

$('.popover2').live('mouseleave', function() { 
    $(this).hide(); 
}); 
相關問題