[英]jQuery .load() doesn't work on a newly created DOM div element
This is my code: 这是我的代码:
$(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);
});
So basically i'm creating a new DOM element with the class name "popContainer" and trying to populate the content from popup.html to it when a user starts to type. 因此,基本上,我正在使用类名称“ popContainer”创建一个新的DOM元素,并尝试在用户开始键入内容时将popup.html中的内容填充到其中。 This isn't working, i tried using .post with no success and i can't figure out if and how .live would be used here.
这是行不通的,我尝试使用.post没有成功,而且我不知道在这里是否以及如何使用.live。
please notice that this file is a part of a chrome extension and that the alert() does work properly. 请注意,此文件是chrome扩展程序的一部分,并且alert()可以正常工作。
I think your load should look something like this.... 我认为您的负载应该看起来像这样。
$('.popContainer').load(chrome.extension.getURL('popup.html'));
also, this question might help you...... 另外,这个问题可能对您有帮助...
With a chrome extension how can add html to just below the body tag of a page? 使用chrome扩展程序,如何将html添加到页面的body标签下面?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.