简体   繁体   English

如何使用jQuery将变量追加到div?

[英]How to append variables to div with jquery?

How to append variables to div with jquery? 如何使用jQuery将变量追加到div? There is my codes below. 下面是我的代码。 But I want to show div tags in append. 但是我想在附录中显示div标签。 For example; 例如; .append("" + p + "") .append(“” + p +“”)

    var image = item.image;
    var label = item.label;
    var price = item.price;
    var vendor = item.vendor;                           

    <div class="image">
        <div>image</div>
        <div class="labelPrice">
            <div>label</div>
            <div>price</div>                                        
        </div>
        <div class="vendor">vendor</div>
    </div>

put id's on your divs and set the html with: 将id放在您的div上,并使用以下代码设置html:

$('#yourLabelId').html(label);
// etc

not sure if this is what you're asking 不知道这是你在问什么

$(".labelPrice").append(item.price); $( “labelPrice。”)追加(item.price)。

This would add it just after the "price" div. 这将在“价格” div之后添加它。

This is the syntax for appending items to an element in JQuery: 这是将项目附加到JQuery中的元素的语法:

$(element).append([HTML Code]);

In this case you want to append certain variables to elements in your document. 在这种情况下,您希望将某些变量附加到文档中的元素。
You may be looking for syntax such as this: 您可能正在寻找这样的语法:

$("#element_id").append([variable]);

Eg: 例如:

$("#label").append(item.label);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM