0
我使用角度js MVC作爲我的前端與html,bootstrap一起使用。我試圖根據搜索關鍵字(ng-model)顯示結果。 我的要求是這樣的,在顯示的結果中,我需要在結果中突出顯示搜索關鍵字。如何突出段落中的特定單詞
我的內容顯示在<p>
標記內。
我使用角度js MVC作爲我的前端與html,bootstrap一起使用。我試圖根據搜索關鍵字(ng-model)顯示結果。 我的要求是這樣的,在顯示的結果中,我需要在結果中突出顯示搜索關鍵字。如何突出段落中的特定單詞
我的內容顯示在<p>
標記內。
的Html
$scope.highlight = function(haystack, needle) {
if(!needle) {
return $sce.trustAsHtml(haystack);
}
return $sce.trustAsHtml(haystack.replace(new RegExp(needle, "gi"), function(match) {
return '<span class="highlightedText">' + match + '</span>';
}));
};
CSS
.highlightedText {
background: red;
}
HTML
<div ng-bind-html="highlight('Nic is cool and smart', 'and')"></div>
great.it worked.thanks很多.... –