2
我試圖建立一個書籤,做以下操作:如何加載外部CSS,JS和從書籤添加一個div到DOM?
1)加載外部JS,位於我的服務器上(進行)
javascript:function%20loadScript(scriptURL)%20{%20var%20scriptElem%20=%20document.createElement('SCRIPT');%20scriptElem.setAttribute('language',%20'JavaScript');%20scriptElem.setAttribute('src',%20scriptURL);%20document.body.appendChild(scriptElem);}%20loadScript('http://127.0.0.1/main.js?x='+Math.random());
2)又將這個外部JavaScript,加載jquery和jquery ui,而不是將div添加到當前網站的DOM中。 (不能得到這個工作)
function loadScripts(scriptURL) {
var scriptElem = document.createElement('SCRIPT');
scriptElem.setAttribute('language', 'JavaScript');
scriptElem.setAttribute('src', scriptURL);
void(document.body.appendChild(scriptElem));
}
loadScripts('http://127.0.0.1/js/jquery-1.3.2.min.js');
loadScripts('http://127.0.0.1/js/jquery-ui-1.7.2.custom.min.js');
var head = document.getElementsByTagName('head')[0];
$(document.createElement('link')).attr({type: 'text/css', href: 'http://127.0.0.1/css/redmond/jquery-ui-1.7.2.custom.css', rel: 'stylesheet'}).appendTo(head);
$(document).ready(function(){
div = $("<div>").html("Loading......");
$("body").prepend(div);
});
我遇到的問題是,我不能追加一個div具有一定的ID,我們的想法是使用對話()jQueryUI的功能,以有一個可調整大小的可移動對話框出現在我使用小書籤的任何網站上。
$("#dialog").dialog();
你可以想象我需要我的內容加載到一個特定的div,所以我不亂了書籤在加載該網站的設計。
3)的對話框,只是打開了一個基本解析頁面的遠程php文件的內容。
腳本完成我只是需要它加載在我試圖構建的對話框中。
請幫助,因爲我真的堅持這一點!謝謝。
謝謝維克多,我只是設法弄清楚那一部分。我已經將div加載到了我的內容中,現在我試圖讓它運行一個遠程php腳本。 – Carvefx 2009-12-21 10:44:00
酷!另外,如果通過運行遠程PHP腳本,你意味着你想進行跨域Ajax調用,你將遇到問題。您還需要從'