jquery .on方法不起作用

时间:2013-03-04 12:28:52

标签: jquery mouseenter

当我在我的div上“onmouseover”时,我会在我的脚本上显示一些视频。因为IE我使用调用mouseenter的jquery函数,但没有任何事情发生。

我的剧本:

jQuery.fn.PlayMovieHome = function () {
    alert("something");
    var co = $(this).children("a").children("img").attr("src").split('images/')[1].split('.')[0];
    var odkaz = $(this).children("a").attr("href");
    $(this).children("a").after("<div id='video' style='position:absolute;width:163px;height:123px;top:5px;'><embed type='application/x-shockwave-flash' src='http://pacogames.com/games/videos/" + co + ".swf' width='163' height='123' wmode='transparent'></embed><a href='" + odkaz + "'><img src='http://pacogames.com/images/163x123.gif' style='position:absolute;left:0px;width:163px;height:123px;top:5px;'></a></div>");
};

jQuery.fn.StopMovieHome = function () {
    $(this).children('#video').remove();
};

$("div#games").on('mouseenter', '.videobox', function () {
    var element = $(this);
    $(element).data('timeouthra', setTimeout(function () {
        $(element).PlayMovieHome();
    }, 250));
});

$("div#games").on('mouseleave', '.videobox', function () {
    var element = $(this);
    clearTimeout($(element).data('timeouthra'));
    $(this).StopMovieHome();
});

html看起来像这样:

<div id="games">
  <li id="videobox-id" class="videobox">
    <a href="/games/nascar.swf">    
    <img class="BOXGAMES_IMG" src="./images/nascar.png" alt="play nascar" style="position: relative; z-index: 1;" /><br />Nascar Racing
    </a>
  </li>
</div>

它不起作用。有谁知道为什么?我错过了什么?

1 个答案:

答案 0 :(得分:1)

试试这个:

$("div#games").on('mouseenter', '.videobox', function () {
    var element = $(this);
    element.data('timeouthra', setTimeout(function () {
        element.PlayMovieHome();
    }, 250));
});

$("div#games").on('mouseleave', '.videobox', function () {
    var element = $(this);
    clearTimeout(element.data('timeouthra'));
    element.StopMovieHome();
});