-1

jqueryの知識がありません。以下のコードが何をするかを教えてくれる人がいますか?私はそれをグーグルで検索しましたが、結果は見つかりませんでした。クラスが「p-notification」の div 内に HTML コンテンツを追加したいと考えています。これを行う方法?

 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'
 });
4

2 に答える 2

1

次の部分は、スコープにプロパティを追加または設定して、 class を持つnotification新しく作成された要素にします。divp-notification

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

次の部分では、スコープのプロパティを追加または設定して、いくつかの属性が事前に設定さcontentれた新しく作成された要素にします: 、、および:divclassstyletext

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

要素を作成しただけでドキュメントに挿入していないため、それ自体では DOM に実質的な影響はありません。jQuery によって提供されるいくつかのメソッドのいずれかを使用して、それらを挿入できますappend

$('#somediv').append(this.content);//adds the div that was created to an element with id somediv
于 2012-11-10T11:11:13.100 に答える
1

コンテンツを追加するには、次のようにします。

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

またはこれでコンテンツを置き換えます:

$('.p-notification').html('<div>Hey</div>');
于 2012-11-10T11:11:39.843 に答える