我正在寻找一种简单的方法来遍历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