[英]jQuery .load() doesn't work on a newly created DOM div element
這是我的代碼:
$(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()可以正常工作。
我認為您的負載應該看起來像這樣。
$('.popContainer').load(chrome.extension.getURL('popup.html'));
另外,這個問題可能對您有幫助...
使用chrome擴展程序,如何將html添加到頁面的body標簽下面?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.