簡體   English   中英

jQuery在整個div塊中搜索字符串

[英]jQuery Search entire div block for string

我有一個帶有各種標簽的代碼塊,但都在一組div標簽內。 我需要能夠搜索div塊中的所有內容,以將字符串替換為另一個。 這是街區。

<div class="form-group field-thoughts-cmh0-thought required">
<label class="control-label" for="thoughts-cmh0-thought">cmh0.</label>
<input type="text" id="thoughts-cmh0-thought" class="form-control" name="Thoughts[cmh0][thought]">
<button type="button" class="entAdd"> Add Above </button> 
<button type="button" class="entDelete"> Delete </button>
<div class="help-block"></div>
</div>

我想做的是用另一個字符串替換所有的“ cmh0”實例。 我知道我可以一個接一個地做,但是隨着時間的流逝,上面的方塊很有可能會改變並且多次改變。 因此,我想要一種優雅的方法來選擇和替換主div塊中的所有“ cmh0”實例。

我該怎么做?

提前致謝。

您可以快速選擇並替換:

var container = $('div[class*="cmh0"]').parent();
container.html(container.html().replace(/cmh0/g, 'someotherclass'));

class*=為“選擇類contanis所在的任何元素”。

然后只需替換html並重新應用即可。

的jsfiddle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM