使用jQuery prePEND问题 [英] issues with jquery prepend
本文介绍了使用jQuery prePEND问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在为什么这是行不通的亏损。
i'm at a loss for why this isn't working..
这个作品:
$(this).prepend("<div data-role='header'><h1>Hi</h1></div>");
然而,当我做我的整个页面变成空白(无负载),但是没有错误:
however when i do this my entire page goes blank (nothing loads), but there's no error:
$(this).prepend("<div data-role='header'><a href='link'>Link</a><h1>Hi</h1></div>");
这也不起作用:
$(this).prepend("<div data-role='header'><h1>Hi</h1></div>");
$(this).find('div[data-role=header]').prepend("<a href='link'>Link</a>");
也没有这样的:
var string = "<div data-role='header'><a href='link'>Link</a><h1>Hi</h1></div>";
$(this).prepend(string);
和这里的,重要的情况下,上下文:
and here's the context in case that matters:
$('div[data-role*="page"]').each(function (i) {
if ($(this).children('div[data-role*="header"]').length != 0) {
alert("has header");
} else {
if (i == 0) {
var string = "<div data-role='header'><a href='link'>Link</a><h1>Hi</h1></div>";
$(this).prepend(string);
} else {
$(this).prepend("<div data-role='header'><h1>Hi</h1></div>");
}
$(this).find('div[data-role=header]').page();
}
});
我如何得到这个工作?
how do i get this to work?
推荐答案
在我的经验,如果脚本中的prePEND功能在使用-tag,它不会因为脚本之前加载工作DOM是准备好了。
In my experience, if the script in which the prepend function is used in the -tag, it will not work because the script is loaded before the DOM is ready.
要避免这种挫折,是一个好习惯的标记之前放置您的JavaScript。
To avoid this kind frustration, is a good habit to place your javascript before the tag.
这篇关于使用jQuery prePEND问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文