【问题标题】:How can I change the color of input tag in a form when focusing on it? [duplicate]关注表单时如何更改表单中输入标签的颜色? [复制]
【发布时间】:2019-12-23 02:40:15
【问题描述】:

我正在使用引导程序为我的网站创建一个联系我们的表单,当用户单击提交并且有一个未填写的必填字段时,它会滚动到该字段并且该字段周围有一个蓝色边框(这会自动发生,这意味着我没有编写任何代码来处理空的必填字段),我希望表单以相同的行为运行,但边框颜色变为红色。

我究竟怎样才能做到这一点?

【问题讨论】:

  • 这和那2个问题不一样

标签: html css forms colors bootstrap-4


【解决方案1】:

添加一个你想要的边框样式的类

if ($("#frm").validationEngine('validate')) {
//add validation criteria as per your requirement

//if it is null value, addd a class to change the border color and focus it
//for exmaple suppose firstname is  the field name,
if($('#firstname').val()=="")
{
$('#firstname').addClass("required");
$('#firstname').focus();
}

}
.required
{
border-color:red;
background:white;
}
<form name="frm">
<input type="text" name="firstname" id="firstname" placeholder="ENTER NAME">
</form>

【讨论】:

    猜你喜欢
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2021-05-03
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 2017-04-28
    相关资源
    最近更新 更多