2010-12-13 73 views
1

我正試圖讓jlembed工作,但我經常在鉻調試器中出錯。我嘗試了所有THIS解決方案,但沒有運氣。哪個是包含jquery和jquery-plugin的正確方法?因爲我試着先把jQuery放到最後。包含jquery插件(jlembed)的問題。與命名空間衝突

這裏是我的SRC代碼版本之一:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript" src="jquery.jlembed.js"></script> 

<script language="javascript" type="text/javascript"> 
    jQuery.noConflict(); 

    jQuery(document).ready(function(){ 
    $("#playerDiv").jlEmbed({ //here is the error (debugger) 
     id : 'player1', 
     youtube : 'Cw2HAD9A_rw', 
     format : 'swfobject', 
     autoplay : 'no', 
     youtubechromeless : 'no', 
     youtubedisplay : true 
    }); 
}); 

</script> 

和療法的錯誤:

Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function 
(anonymous function) 
jQuery.jQuery.extend.readyjquery-latest.js:447 
jQuery.DOMContentLoaded 

EDIT2:答:

我發現基於THIS正確的語法。

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript" src="jquery.jlembed.js"></script> 

<script language="javascript" type="text/javascript"> 
    jQuery(document).ready(function(){ 
     //jQuery("").hide(); 
    }); 

    jQuery(document).ready(function(){ 
    $("#playerDiv").jlEmbed({ 
     id : 'player1', 
     youtube : 'Cw2HAD9A_rw', 
     format : 'swfobject', 
     autoplay : 'no', 
     youtubechromeless : 'no', 
     youtubedisplay : true 
    }); 
}); 
</script> 
+0

jQuery肯定要排在第一位。你得到的錯誤是什麼? – 2010-12-13 15:07:04

+0

嘿,我編輯我的問題與錯誤 – vale4674 2010-12-13 15:28:34

回答

1

你爲什麼叫noConflict。然後使用jQuery作爲準備好的文檔。然後在$(「#playerDiv」)/

上再次使用正常的$ jquery選擇器,嘗試將該$更改爲jQuery。

+0

嘿,我剛剛用這個解決方案編輯了我的問題(在你的答案後2秒發佈)。你之前在哪裏:(tnx無論如何 – vale4674 2010-12-13 16:08:08

0

不知道這是否解決了這個問題,因爲我們不知道你的錯誤:

  1. 第一把jQuery的:

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
    <script type="text/javascript" src="jquery.jlembed.js"></script> 
    
  2. $("#playerDiv").jlEmbed({...})已去進入回調呢!

    jQuery(document).ready(function(){ 
        $("#playerDiv").jlEmbed({ 
         id : 'player1', 
         youtube : 'Cw2HAD9A_rw', 
         format : 'swfobject', 
         autoplay : 'no', 
         youtubechromeless : 'no', 
         youtubedisplay : true 
        }); 
    }); 
    

    否則$("#playerDiv")會嘗試與ID #playerDiv找到元素被創建之前。

+0

我編輯我的問題與你的靈魂,但我仍然得到錯誤。我也編輯過。 – vale4674 2010-12-13 15:19:37

1

確定您實際上包含jlEmbed AFTER jQuery,但在jQuery(document).ready腳本之前。

您的jlEmbed副本是否與您正在使用的頁面位於相同的位置? -

<script type="text/javascript" src="jquery.jlembed.js"></script> 

嘗試插入jlEmbed的完整路徑而不是相對路徑。

<script type="text/javascript" src="http://jlembed.com/latest.js"></script> 
+0

我發現了這個結果,實際上它出現在你的網站上,但是我做了一些錯誤的事情,在我修好之後,我用解決方案編輯了我的問題。 – vale4674 2010-12-26 14:22:41