0

「delete.png」ではないすべての画像を見つけ、その画像をsrc「active.png」に変更します。

$("img.sign[src!='delete.png']").attr({ 'src': 'active.png', 'alt': 'Active' });

<p>画像を変更したら、その下のテキストも「アクティブ」に変更したいと思います。

前:

<td class="TableTD">
<p style="display:inline;" class="yellow" title="<p style='margin-top:0px;font-
size:12px;margin-bottom:0px;padding-bottom:0px'>Active</p>">
<img alt="Active" src="active.png" class="sign"/>
</p></td>

<td class="TableTD">
<p style="display:inline;" class="yellow" title="<p style='margin-top:0px;font-
size:12px;margin-bottom:0px;padding-bottom:0px'>Pause</p>">
<img alt="Pause" src="pause.png" class="sign"/>
</p></td>

<td class="TableTD">
<p style="display:inline;" class="yellow" title="<p style='margin-top:0px;font-
size:12px;margin-bottom:0px;padding-bottom:0px'>Delete</p>">
<img alt="Delete" src="delete.png" class="sign"/>
</p></td>

後:

<td class="TableTD">
<p style="display:inline;" class="yellow" title="<p style='margin-top:0px;font-
size:12px;margin-bottom:0px;padding-bottom:0px'>Active</p>">
<img alt="Active" src="active.png" class="sign"/>
</p></td>

<td class="TableTD">
<p style="display:inline;" class="yellow" title="<p style='margin-top:0px;font-
size:12px;margin-bottom:0px;padding-bottom:0px'>Active</p>">
<img alt="Active" src="active.png" class="sign"/>
</p></td>

<td class="TableTD">
<p style="display:inline;" class="yellow" title="<p style='margin-top:0px;font-
size:12px;margin-bottom:0px;padding-bottom:0px'>Delete</p>">
<img alt="Delete" src="delete.png" class="sign"/>
</p></td>

私は次のようなものを書くことを考えました:

$("td.TableTd p").innerHTML = 'Active'

しかし、それは最後のtdを変更します..

アップデート:

例えば:

<p style="display:inline;" class="yellow" title="<p style='margin-top:0px;font-
size:12px;margin-bottom:0px;padding-bottom:0px'>Pause</p>">

私は言葉を変えたい:PauseなるActive

4

4 に答える 4

1

<p>「その下のテキストも「アクティブ」に変更したい」

「その下」と言うと、親の属性<p>内のテキストについて話しているようです。(ホバー時にそのコンテンツを実際の要素に変えるある種のツールチッププラグインを使用していると思います。)もしそうなら、これを行うことができます:title<p>title

$("img.sign[src!='delete.png']").attr({
    'src': 'active.png', 'alt': 'Active'
}).closest('p').attr('title', function(i, oldVal) {
    return oldVal.replace(/>[^<]*</, '>Active<');
});

(一般的な規則として、html を正規表現で解析するのは良い計画ではありませんが、この特定のケースでは十分に安全なはずです。)

デモ: http://jsfiddle.net/CT6wU/

于 2013-06-12T11:13:55.737 に答える
1

試す:

$("img.sign[src!='delete.png']").
            parent('p').title = 
                '<p style="margin-top:0px;font-size:12px;margin-bottom:0px;padding-bottom:0px">Active</p>'
于 2013-06-12T11:11:19.980 に答える