为新闻标题加颜色
<asp:TextBox id="txtTitle" runat="server" Height="20" CssClass="title txt300"></asp:TextBox>
<select id="selColor" style="width: 96px">
<option value="" selected>默认颜色</option>
<option value="#000000" style="background-color:#000000;"></option>
<option value="#D2691E" style="background-color:#D2691E;"></option>
<option value="#DC143C" style="background-color:#DC143C;"></option>
<option value="#006400" style="background-color:#006400;"></option>
<option value="#1E90FF" style="background-color:#1E90FF;"></option>
<option value="#7FFFD4" style="background-color:#7FFFD4;"></option>
<option value="#FFA07A" style="background-color:#FFA07A;"></option>
<option value="#DCDCDC" style="background-color:#DCDCDC;"></option>
<option value="#F5F5DC" style="background-color:#F5F5DC;"></option>
<option value="#FFE4C4" style="background-color:#FFE4C4;"></option>
<option value="#B0E0E6" style="background-color:#B0E0E6;"></option>
<option value="#FF0000" style="background-color:#FF0000;"></option>
<option value="#008000" style="background-color:#008000;"></option>
<option value="#808080" style="background-color:#808080;"></option>
<option value="#7CFC00" style="background-color:#7CFC00;"></option>
<option value="#FFE4E1" style="background-color:#FFE4E1;"></option>
<option value="#FFA500" style="background-color:#FFA500;"></option>
<option value="#008080" style="background-color:#008080;"></option>
<option value="#FFFFFF" style="background-color:#FFFFFF;"></option>
</select>
javascript:
function ChangeColor(colorObj)
{
var filter = /<font[\s|\S]*?>(.*?)<\/font>/gi;//过滤点html标签
var text=$("txtTitle").value;
colorValue=colorObj.value;
$("txtColor").value =colorValue;
$("selColor").style.background=colorValue;
if(text!="")
{
if(filter.test(text))
{
if(colorValue=="")
{
$("txtTitle").value=text.replace(filter,"$1");
}
else
{
$("txtTitle").value="<font color='"+colorValue+"'>"+text.replace(filter,"$1")+"</font>";
}
}
else
{
$("txtTitle").value="<font color='"+colorValue+"'>"+text+"</font>";
}
}
}