JQuery prependTo 和appendTo 无结果
以下代码应该在每个元素 .scrollable 中添加一些代码。每个元素应该在 .scrollable 中的第一行位于已存在的内容之前,第二行位于已存在的内容之后。
$('.scrollable').addClass('tny');
$('<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div><div class="viewport"><div class="overview">').prependTo('.scrollable');
$('arse').appendTo('.scrollable');
相反,所有内容都丢失了。我做错了什么?
抱歉,这是之前的测试
$('.scrollable').addClass('tny');
$('<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div><div class="viewport"><div class="overview">').prependTo('.scrollable');
$('</div></div>').appendTo('.scrollable');
这就是它目前的样子
The following code is supposed to add some code inside each element .scrollable. Each element should have the first lines inside .scrollable before the already existing content and the second after the already existing content.
$('.scrollable').addClass('tny');
$('<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div><div class="viewport"><div class="overview">').prependTo('.scrollable');
$('arse').appendTo('.scrollable');
Instead all the content is missing. What did I get wrong?
Sorry that was a test from earlier
$('.scrollable').addClass('tny');
$('<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div><div class="viewport"><div class="overview">').prependTo('.scrollable');
$('</div></div>').appendTo('.scrollable');
That is how it currently looks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能
prepend()
开始标记和append()
结束标记。这些方法仅适用于“完整”元素。您应该使用 wrapInner() 代替:
You cannot
prepend()
start tags andappend()
end tags. These methods only work with "complete" elements.You should use wrapInner() instead:
因为您必须将 'arse' 替换为
arse
。更新:
嗯,这是不正确的:
$('').appendTo('.scrollable');
您必须在第一个 prependto 中包含那些结束 div查询,那么如果您想在这些新创建的 div 中包含某些内容,只需使用 jquery 调用它们并在其中插入您想要的内容即可
Because you have to replace 'arse' with
<span>arse</span>
.update:
well, that's not correct:
$('</div></div>').appendTo('.scrollable');
you have to include those closing divs in the first prependto query, then if you want to include something in those newly created divs, just call them with jquery and insert the stuff you want inside them