开发者

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");
                }
            });

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?

here is my lstCodelist box code.

  <select id="lstCodelist" size="17" name="lstCodelist" style="width:100%开发者_如何学Go;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");

should be

$("#lstCodelist").css("background-color", "#ffffff");

.val() returns a value, not the original jQuery object.

To change the font color, you wold use:

$("#lstCodelist").css("color", "#00ffff");


                $("#lstCodelist").val(x).css("background-color", "#ffffff");

should be

                $("#lstCodelist").css("background-color", "#ffffff");

Otherwise you're trying to set a css property on whatever string/number the .val() call returns, and NOT on the actual page element that the value's coming from.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜