2013-08-24 42 views
0

HTML:的jQuery訪問DOM - 混合內容安全

<section id="playing" class="gradient"> 
<div id="playing-header"> … </div> 
<div id="playing-carousel"> … </div> 
<div id="playing-info"> 
    <a id="radio-star" class="" href="radio:star"></a> 
    <div id="radio-track-info"> 
     <h2 id="radio-track"> … </h2> 
     <h2 id="radio-artist"> 
      <a class="outgoing"> 
    JAY Z 
      </a> 
     </h2> 
    </div> 
    <div id="thumb-container"> … </div> 
</div> 
<div id="loading" style="display: none;"></div> 
<div id="loading-throbber" style="display: none;"></div> 
<div id="station-error" style="visibility: hidden;"> … </div> 

的jQuery:

alert($('#radio-artist .outgoing').text()); 

的jsfiddle: http://jsfiddle.net/CT95N/

工程上的jsfiddle,但不能在網站。返回空。可能是什麼問題呢?在dom之後,我可以檢查什麼來調用我的jquery?

感謝

編輯: $(文件)。就緒(函數(){};當然已經叫在開始的,所以這是不是問題的關鍵

的問題。 FIREFOX阻止了內容,因爲我在https網站上工作,並試圖從該網站獲取一些數據。由於該網站不使用jQuery,我必須自行追加它,這意味着我在https內添加http內容我認爲這是因爲我通過greasemonkey腳本從谷歌添加jquery外部源(附加)

這是警告: http://i.imgur.com/oV19dFz.png

我可以以某種方式做這更好的辦法?

+0

正如你所說,它是在小提琴中工作;看起來很可能你有一個錯誤或在DOM準備好時加載jQuery的問題。 – cantera

+0

是DOM準備好之後或之前執行的警報嗎?當警報執行時,您的元素很可能還沒有準備好。 – Harry

+0

garry你能告訴我該如何ch3eck? –

回答

0

最有可能的答案是,文件還沒有準備好,你應該等待直到該文檔被加載:「可我查打電話給我的jquery DOM以後有什麼」

$(document).ready(function() { 
    alert($('#radio-artist .outgoing').text()); 
}); 
+0

請檢查編輯 –

0

我認爲這意味着你沒有用任何東西包裝這個警報。您很可能需要確保只在文檔/ DOM準備好並呈現後才調用該函數。 jsfiddle可以工作,因爲它們很可能會在源代碼片段中簡潔地添加此包裝。

$(document).ready(function() { 
    alert(....); 
}); 
+0

請檢查編輯 –

0

試試這個代碼

$(document).ready(function(){ 
alert($('#radio-artist .outgoing').text()); 
}); 

根據這個代碼,當DOM就緒時,jQuery將調用。

+0

請檢查編輯 –

0

好吧,算了一下。當你使用https工作時,你必須從hTTPS而不是HTTP追加jQuery CDN:

function appendjQuery(){ 
    var script = document.createElement("script"); 
    script.type = "text/javascript"; 
    script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"; 
    document.body.appendChild(script); 
    document.body.removeChild(script); 
    } 

乾杯。