我希望文本框有红色边框 [英] I want the textbox to have red borders

查看:49
本文介绍了我希望文本框有红色边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户提交表单而不在文本框中指定值时,如何使文本框边框呈红色,我希望文本框有红色边框。

How to make textbox border red in colour when the user submits the form without specifying a value in the textbox, I want the textbox to have red borders.

推荐答案

你可以试试这个:

你的HTML代码:

you can try this:
your html code:
 <asp:textbox id="txtName" runat="server"></asp:textbox>
 <asp:button id="btnSave" runat="server" text="Save"

             OnClientClick="return validate();" />
</asp:button>





你的javascript函数:



your javascript function:

function validate() {
    var txt = document.getElementById('<%= txtName.ClientID %>');
    if (txt.value == "") {
        txt.style.border = "1px solid Red";
        return false;
    }
 }







祝你好运。




Good luck.


当控件的验证失败时 - 它会在html中为控件添加一个css类。查看您呈现的html(右键单击浏览器 - >查看源代码)并查看TextBox的类。然后编辑你的css以包含失败验证的新样式。

像这样:

When validation fails for a control - it''ll add a css class to the control in the html. Look at your rendered html(Right click on browser --> View Source) and check out the class for TextBox. Then edit your css to include a new style for the failed validation.
Like this:
input.input-validation-error,
textarea.input-validation-error,
select.input-validation-error
{
    background: #FEF1EC;
    border: 1px solid #CD0A0A;
}







- 发送




--Amit


这篇关于我希望文本框有红色边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆