我正在尋找一種簡單的方法來遍歷Angularjs中給定字符串的DOM(或元素)。如果找到給定的字符串,我想粗體顯示它的文本。因爲我還沒有提出解決方案,所以我覺得我已經過時了。在Angularjs中掃描DOM的字符串
例如
搜索狗應該返回4個結果
<section id="container">
<div>
<h2>Dogs are great</h2>
<p>They are the best. Everyone should have a dog</p>
<div>
<p>Cat owners are just confused dog owners</p>
<p>What's your doggos name?</p>
</div>
</div>
</section>
<script>
$scope.search = function(word){
var entireDom = // Get the entire innerText of the <section>
if(entireDom.match(word) {
// Wrap the string in <strong> tags & update the DOM somehow?
// This function should probably be case insensitive
}
}
<script>
任何意見或建議將是超級有用。謝謝!
請參閱[如何從正則表達式替換中排除jpeg名稱?](https://stackoverflow.com/q/41057212/) – guest271314