有没有办法自动设置单词?
我想创建一个代码,每当我写一个特定的单词,如" fire"和"冰"分别采用红色和蓝色,而不是像spawn,p等标签之间。这可能吗?
答案 0 :(得分:1)
您可以使用jquery:
这是一个例子。
class SomeController
def some_method
if catch(:abort) { mode.save }
# success
else
# failure
end
end
end

var StringFire = 'Fire',
newStringFire = '<span>Fire</span>',
newTextFire = $('p').text().replace(RegExp(StringFire,"gi"),newStringFire);
$('p').html(newTextFire);
&#13;
span{
color: red;
font-family: sans-serif;
}
&#13;
对于多个单词:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Fire and Ice. Launch Audio in a New Window. By Robert Frost. Some say the world will end in fire,. Some say in ice. From what I've tasted of desire. I hold with those who favor fire. But if it had to perish twice,. I think I know enough of hate. To say that for destruction ice. Is also great. And would suffice. n/a. More About this ...</p>
&#13;
var text = $('p').html().replace(/Ice/gi, "<span class='ice'>Ice</span>");
$('p').html(text);
var text = $('p').html().replace(/Fire/gi, "<span class='fire'>Fire</span>");
$('p').html(text);
&#13;
.ice {
color: blue;
font: sans-serif;
}
.fire {
color: red;
font: sans-serif;
}
&#13;
答案 1 :(得分:-1)
也许使用脚本?
$(document).ready(function(){
$('#searchfor').keyup(function(){
page = $('#all_text').text();
searchedText = $('#searchfor').val();
$("p:contains('"+searchedText+"')").css("color", "red");
});
});