Jquery在IE中不起作用

时间:2011-01-10 01:59:39

标签: jquery internet-explorer

请参阅:http://qwer.se/stack/trailer/

它在FF,C& SF但不在IE中。无法找到错误。

IE说:“'undefined'为null或不是对象”

这是剧本:

<script>
$(document).ready(function(){

// open popup when image is clicked
$('img').click(function(){
var $movieObj = $(".tdt object"); // Cache jQuery object
var imgID = $(this).attr("alt"),
    movieVal = $("param[name=movie]", $movieObj).val(),
    embedSrc = $("embed", $movieObj).attr("src");
$movieObj
    .find("param[name=movie]").val(movieVal.replace(/MY-ID-NUMBER/, imgID)).end()
    .find("embed", $movieObj).attr("src", embedSrc.replace(/MY-ID-NUMBER/, imgID)).end();
$(".tdb").show();
});


// close popup + restor value to default
$('.tdb').click(function(){
var default1 = "http://www.player.filmtrailer.com/v3.4/player.swf?file=http://se.player-feed.previewnetworks.com/cinema/MY-ID-NUMBER/4601100213-1/";
var default2 = "http://www.player.filmtrailer.com/v3.4/player.swf?file=http://se.player-feed.previewnetworks.com/cinema/MY-ID-NUMBER/4601100213-1/&display_title=over&menu=true&enable_link=true&default_quality=xxlarge&controlbar=over&autostart=true&backcolor=000000&frontcolor=ffffff&share=0&repeat=always&displayclick=play&volume=80&linktarget=_blank";
var $movieObj = $(".tdt object"); // Cache jQuery object
var imgID = $(this).attr("alt"),
movieVal = $("param[name=movie]", $movieObj).val(),
embedSrc = $("embed", $movieObj).attr("src");
$(".tdt object").find("param[name=movie]").val(default1);
$(".tdt object").find("embed", $movieObj).attr("src", default2);
$(".tdb").hide();
});

});
</script>

我已将ID添加到“param”和“embed”,并且现在也将脚本更改为此内容。但它仍然无法在IE中使用。

// open popup when image is clicked
$('img').click(function(){
var $movieObj = $(".tdt object"); // Cache jQuery object
var imgID = $(this).attr("alt"),
    movieVal = $('#testing').val(),
    embedSrc = $('#player').attr("src");
$movieObj
    .find('#testing').val(movieVal.replace(/MY-ID-NUMBER/, imgID)).end()
    .find('#player').attr("src", embedSrc.replace(/MY-ID-NUMBER/, imgID)).end();
$(".tdb").show();
});


// close popup when background is clicked + restor value to default
$('.tdb').click(function(){
var default1 = "http://www.player.filmtrailer.com/v3.4/player.swf?file=http://se.player-feed.previewnetworks.com/cinema/MY-ID-NUMBER/4601100213-1/";
var default2 = "http://www.player.filmtrailer.com/v3.4/player.swf?file=http://se.player-feed.previewnetworks.com/cinema/MY-ID-NUMBER/4601100213-1/&display_title=over&menu=true&enable_link=true&default_quality=xxlarge&controlbar=over&autostart=true&backcolor=000000&frontcolor=ffffff&share=0&repeat=always&displayclick=play&volume=80&linktarget=_blank";
var $movieObj = $(".tdt object"); // Cache jQuery object
var imgID = $(this).attr("alt"),
    movieVal = $('#testing').val(),
    embedSrc = $('#player').attr("src");
$movieObj
    .find('#testing').val(default1).end()
    .find('#player').attr("src", default2).end();
$(".tdb").hide();
});

这是我解决它的方式(可能不是虔诚,但它有效):

$('img').click(function(){
var default1 = '<object class="tot" width="960" height="540"><param id="testa" name="movie" value="http://www.player.filmtrailer.com/v3.4/player.swf?file=http://se.player-feed.previewnetworks.com/cinema/';
var default2 = $(this).attr("alt");
var default3 = '/4601100213-1/><param name="wmode" value="transparent" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><embed id="player" name="player" type="application/x-shockwave-flash" src="http://www.player.filmtrailer.com/v3.4/player.swf?file=http://se.player-feed.previewnetworks.com/cinema/';
var default4 = '/4601100213-1/&display_title=over&menu=true&enable_link=true&default_quality=xxlarge&controlbar=over&autostart=true&backcolor=000000&frontcolor=ffffff&share=0&repeat=always&displayclick=play&volume=80&linktarget=_blank" width="960" height="540"allowFullScreen="true" allowScriptAccess="always"></embed></object>';
$('.tdt').html(default1 + default2 + default3 + default2 + default4);
$(".tdb").show();
});



$('.tdb').click(function(){
$('.tdt').html('');
$(".tdb").hide();
});

1 个答案:

答案 0 :(得分:0)

使用IE调试器显示此位引发错误:

$movieObj
    .find("param[name=movie]").val(movieVal.replace(/MY-ID-NUMBER/, imgID)).end()
    .find("embed", $movieObj).attr("src", embedSrc.replace(/MY-ID-NUMBER/, imgID)).end();

查看IE开发工具中的来源显示param标记内没有object个标记,并且嵌入标记已经过时(</embed/>)。我不确定是什么导致了这一点。

[shotInTheDark] <embed>是一个自动关闭的标签,也许IE正在混淆你的非自动关闭标签。[/ shotInTheDark]