我需要根据下拉列表选择更改文本的颜色。
<select id="room2">
<option>#0808cf</option>
<option>#0E9E26</option>
</select>
<input type="text" id="txtColor">
John: <p style="color:#0808cf" > test </p>
jQuery
$('#colors').change(function(){
$('#txtColor').val($("#colors").val());
var fontColor = $('#txtColor').val();
});
我不希望更改出现在 css 中,因为选择 id 不会是恒定的。我希望它被插入到 p 样式标签中。而且我还需要文本是约翰:测试在一行中。我试过这个但没有工作。谢谢你。
<p style="color:"+fontColor+" > test </p>
演示:http: //jsfiddle.net/kX3EN/