-1

スパン クラス内のコンテンツを jquery に置き換えようとしています。最初の行が機能するため、jquery ファイルが読み取られていることがわかります。基本的に、jquery の最初の行は、通知のリストに新しい通知を追加します。クエリの 2 行目は、サイトの既存の番号を新しい @unseen_notifications.count に置き換える必要があります。jquery ファイルの 2 行目が機能していません。どうすれば修正できますか?

jquery:

$('#user_notifications').prepend("<%= j render(@user_notifications) %>");
$('#red-count').html.replaceWith("<%= @unseen_notifications.count %>");

html:

<span class="red-count">
    <%= @unseen_notifications.count %>
</span>
4

3 に答える 3

2
<span class="red-count">
    <%= @unseen_notifications.count %>
</span>

$('.red-count').html("<%= @unseen_notifications.count %>");

.代わりにクラスを使用している場合#

特定の要素のhtml/コンテンツを変更したい場合は、使用できます

$('YOUR ELEMENT SELECTOR').html('YOUR CONTENT')

テキストを追加するだけの場合は、次も使用でき.text()ます

 $('YOUR ELEMENT SELECTOR').text('YOUR TEXT')
于 2013-12-12T20:47:09.103 に答える
1

書くことはできませんhtml.replaceWith。以下のようにhtmlを設定します

$('.red-count').html("<%= @unseen_notifications.count %>");

また、 red-count はクラスなので、.代わりに使用します#

于 2013-12-12T20:46:23.250 に答える