jQuery .append(),prepend(),after()...重复的元素和内容? [英] jQuery .append(), prepend(), after() ... duplicate elements and contents?

查看:506
本文介绍了jQuery .append(),prepend(),after()...重复的元素和内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,该命令仅运行一次:

In my code this command is run only once:

jQuery("#commentrating").append('A');

,但是在div #commentrating内出现了两个"A"元素!是什么导致此错误?

but inside the div #commentrating there appears two "A" elements! What may be causing this bug?

P.S. .after()也是越野车:S

P.S. .after() is buggy as well :S

推荐答案

两个可能的原因:

(使用 append appendTo prepend prependTo 时). ..):

Two possible causes:

(when using append, appendTo, prepend, prependTo ...):

1)如果将2个元素附加到1个目标元素,则使用:

1) If you attach 2 source elements to 1 destination element, if you use:

$("destination").append("source");

在您的html中的某个位置上的jQuery找到2个source_div元素,并将它们都追加.

jQuery somewhere in your html finds 2 source_div elements and appends both of them.

2)如果您将1个元素附加到2个目标,例如:

2) If you attach 1 source element to 2 destination, like:

$("destination").append("source");

可能在您的html中有2个destination元素:

probably in your html you have 2 destination elements:

<div>
    <div class="destination"></div>
    ......
    <div class="destination"></div>
</div>

这篇关于jQuery .append(),prepend(),after()...重复的元素和内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆