2011-01-10 228 views
0

參見:http://qwer.se/stack/trailer/jQuery的不工作在IE

它工作正常,在FF,C & SF但不是在IE瀏覽器。不能找到錯誤。

IE表示:「‘未定義’是空或不是對象」

這是腳本:

<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到「參數」和「嵌入」,並且還現在把腳本改成這個了。但它在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(); 
}); 

這是我sloved它(可能不是prity,但它的工作原理):

$('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(); 
}); 
+0

在[shotInTheDark /]哪一行IE說的是有錯誤? – amosrivera 2011-01-10 03:20:30

+0

對不起amosrivera,沒有你的評論。我現在已經以其他方式解決了代碼。將盡快更新問題。如果你想要你可以評論新的解決方案(它可能不是純正的,但它的工作原理) – Hakan 2011-01-10 03:43:35

回答

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開發工具的源代碼,發現object標籤內部沒有任何param標籤,並且嵌入標籤被盜用(</embed/>)。我不確定是什麼原因造成的。

[shotInTheDark] <embed>是一個自閉的標籤,也許IE瀏覽器錯亂的非自關閉標籤。