替换dom元素中的所有字符串

Rob*_*rto 1 jquery replace

我有一块像这样的DOM

<table style="display:none;" id="risposta-campione">
<tr>
<td>
    <label>Risposta</label><textarea id="risposta_0000" name="risposta_0000" cols="35" rows="2"></textarea>
    <button type="button" onclick="cancellaRispostaDomanda('0000')" class="cancella-risposta"></button>
    <button type="button" onclick="aggiungiRispostaDomanda('0000')" class="aggiungi-risposta"></button>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我想用jquery替换所有'0000'出现而不获取每个元素.

这可能吗?

我试过这个:

elem = $('#risposta-campione').text() // how convert dom to string?!
elem.replace('0000', 'hello');
Run Code Online (Sandbox Code Playgroud)

没有解决方案: - /

Aar*_*lla 5

使用 $('#risposta-campione').html().replace('0000', 'hello');


小智 5

strings = $('#risposta-campione').html();
strings = strings.replace(/0000/g,"hello");
Run Code Online (Sandbox Code Playgroud)

这将取代所有的次数0000hello.