2
這是我的代碼:jQuery的.load()不新創建的DOM div元素上工作
$(document).ready(function(){
var searchDom = document.createElement('div');
searchDom.className = "popContainer";
searchDom.style.cssText = [
'background-color: #ffd700;',
'background-image: -webkit-repeating-linear-gradient(' +
'45deg, transparent, transparent 35px,' +
'rgba(0,0,0,.1) 35px, rgba(0,0,0,.1) 70px);',
'color: #efefef;',
'padding: 10px;',
'font: 14px Arial;'
].join(' ');
document.body.style.cssText = 'position: relative';
document.body.parentElement.insertBefore(searchDom, document.body);
var greeting = "hola";
var button = document.getElementById("navSearch");
button.person_name = "Roberto";
button.addEventListener("keydown", function() {
$('.popContainer').load('popup.html');
alert(greeting);
}, false);
});
所以基本上我創建與類名「popContainer」一個新的DOM元素,並試圖當用戶開始輸入時,將popup.html中的內容填充到它。這是行不通的,我嘗試使用.post沒有成功,我不知道是否和如何.live會在這裏使用。
請注意,此文件是Chrome擴展的一部分,並且alert()確實正常工作。
你真的想要添加* body元素之前的新元素* – 2012-02-01 02:35:03
目前是的,因爲我不知道我使用這個擴展的網站如何使用他們的JS,風格等。 – Tom 2012-02-01 02:37:31
Chrome的開發工具是否有錯誤? – abraham 2012-02-01 02:39:07