如何使用jQuery更改文本颜色 [英] how to change the text color using using jquery
问题描述
function DoInsert(ind) {
var sourceIndex = $("#lstAvailableCode").val();
var targetIndex = $("#lstCodelist").val();
var success = 0;
var rightSelectedIndex = $("#lstCodelist").get(0).selectedIndex;
var functionName = "/Ajax/SaveCodeforInsert";
if (ind == "plan") {
functionName = "/Ajax/SaveCodeforInsertForPlan";
}
$.ajax({
type: "POST",
traditional: true,
url: functionName,
async: false,
data: "ControlPlanNum=" + $("#ddControlPlan").val() + "&LevelNum=" + $("#ddlLevel").val() + "&ColumnNum=" + $("#ddlColumn").val() + "&SourcbaObjectID=" + sourceIndex + "&TargetbaObjectID=" + targetIndex + "&userID=<%=Model.userID%>",
dataType: "json",
error: function (data) {
alert("Error Adding Code");
FinishAjaxLoading();
},
success: function (data) {
if (data == 0) { success = 1; } else { success = data; }
FinishAjaxLoading();
var x = $("#lstAvailableCode").val();
$("#lstCodelist").val(x);
$("#lstCodelist").val(x).css("background-color", "#ffffff");
}
});
在这里,我尝试将lstAvailableCode列表框中的一项添加到lstCodelist框中.添加到lstCodelist框中后,我试图将textcolor更改为黄色或其他某种颜色. 在我的成功信息中,我写了这样的话.但是,即使我不能更改该列表框的背景色,也无法更改文本的颜色.这是我在做错什么吗?
Here I am trying to adding one item from lstAvailableCode list box to lstCodelist box. after adding into lstCodelist box I am trying to change the textcolor to yellow or some other color. on my success message i wrote something like this. But I am not able to change the color of the text even I am not able to change the backgroud color of that list box. is that something I am doing wrong here?
这是我的lstCodelist框代码.
here is my lstCodelist box code.
<select id="lstCodelist" size="17" name="lstCodelist" style="width:100%;height:280px;background-color:#EFEFFB;"></select>
$.fn.fillSelectDD = function (data) {
return this.clearSelectDD().each(function () {
if (this.tagName == 'SELECT') {
var dropdownList = this;
$.each(data, function (index, optionData) {
var option = new Option(optionData.Text, optionData.Value);
if ($.browser.msie) {
dropdownList.add(option);
}
else {
dropdownList.add(option, null);
}
});
}
});
}
推荐答案
$("#lstCodelist").val(x).css("background-color", "#ffffff");
应该是
$("#lstCodelist").css("background-color", "#ffffff");
.val()
返回一个值,而不是原始的jQuery对象.
.val()
returns a value, not the original jQuery object.
要更改字体颜色,请使用:
To change the font color, you wold use:
$("#lstCodelist").css("color", "#00ffff");
这篇关于如何使用jQuery更改文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!