【问题标题】:How to put a color in html textbox with a condition?如何在带有条件的html文本框中输入颜色?
【发布时间】:2016-07-11 08:26:18
【问题描述】:

大家好,如何在 cshtml 中更改文本框的颜色?我有这个代码

$("#BUTTON").click(function (event) {
    var urlPA = URL;
    var crty = $("#Courtesy").val();
    var fname = $("#Familyname").val();
    var gname = $("#GivenName").val();

    if (crty != 0 && fname != 0 && gname != 0) {
        $.ajax({
            type: "GET",
            url: urlPA,

            data: 'DATA',
            success: function (response) {
                alert(response);
            /// when success the color of the textbox return to normal
            },
            datatype: "text"
        });
    } else { alert("Please fill up the required fields.");
     ////// when error the textbox background makes red

}
});

怎么做?谢谢。

【问题讨论】:

  • @GiladGreen 与众不同。我有一个条件,文本框是否会改变颜色。请参阅代码示例。

标签: javascript jquery html jqgrid-asp.net


【解决方案1】:

您可以使用 jQuery 的css 函数来设置内联样式:

if (crty != 0 && fname != 0 && gname != 0) {
    $.ajax({
        type: "GET",
        url: urlPA,

        data: 'DATA',
        success: function (response) {
            alert(response);
            /// when success the color of the textbox return to normal
            $('#Courtesy').css('background-color', 'white');
            // add other fields
        },
        datatype: "text"
    });
} else { alert("Please fill up the required fields.");
    ////// when error the textbox background makes red
    $('#Courtesy').css('background-color', 'red');
    // add other fields
}

【讨论】:

  • 非常感谢。我现在明白我的错误了。它工作正常。 +1
猜你喜欢
  • 2014-04-24
  • 1970-01-01
  • 2015-02-08
  • 2021-03-22
  • 2016-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多