2012-07-03 21 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(); 
}); 
相关问题