简体   繁体   English

创建DIV元素并添加HTML内容

[英]Creating DIV elements and adding HTML Contents

I have no knowledge in jquery. 我对jquery不了解。 can some body guide me what the below code does. 某些机构可以指导我下面的代码做什么。 I googled it but no result found. 我用谷歌搜索,但没有找到结果。 I want to add some HTML Contents inside the div whose class is 'p-notification'. 我想在div类为'p-notification'的div中添加一些HTML内容。 How to do this? 这个怎么做?

 this.notification = $('<div/>', {
            'class': 'p-notification'
 });
 this.content = $('<div/>', {
        'class': $elem.attr("hasFooter") === "true" ? 'p-content with-p-footer' : 'well',
        'style': $elem.attr("paddless") === "true" ? 'padding:0;' : '',     
        'text': 'Loading'
 });

The following part adds or sets the notification property on the scope to be a newly created div element with class p-notification : 以下部分在范围上添加或设置notification属性,使其成为具有p-notification类的新创建的div元素:

 this.notification = $('<div/>', {
            'class': 'p-notification'
 });

The next part adds or sets the content property on the scope to be a newly created div element with several attributes being preset: class , style , and text : 下一部分将在范围上添加或设置content属性为一个新创建的div元素,并预先设置了几个属性: classstyletext

 this.content = $('<div/>', {
        'class': $elem.attr("hasFooter") === "true" ? 'p-content with-p-footer' : 'well',
        'style': $elem.attr("paddless") === "true" ? 'padding:0;' : '',     
        'text': 'Loading'
 });

By itself this will have no net effect on the DOM, since you have created elements but not inserted them into the document. 就其本身而言,这不会对DOM产生任何影响,因为您已经创建了元素但未将其插入文档中。 You can insert them by using one of several methods provided by jQuery, eg append : 您可以使用jQuery提供的几种方法之一来插入它们,例如append

$('#somediv').append(this.content);//adds the div that was created to an element with id somediv

You could do like this to add content: 您可以这样添加内容:

$('.p-notification').append('<div>Hey</div>');

or this to replace content: 或替换内容:

$('.p-notification').html('<div>Hey</div>');

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

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