使用 twitter bootstrap 等 jquery 突出显示错误的输入字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20266941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Highlight the input field for error with jquery like twitter bootstrap
提问by Shiva Krishna Bavandla
I have the below sample html code, where i am trying to highlight the input field like input field validation in twitter bootstrap
我有以下示例 html 代码,我试图在其中突出显示输入字段,例如 twitter bootstrap 中的输入字段验证
<html>
<head>
$('#submit_form').submit(function(){
var vals = $('.validate').val()
if (!vals)
{
console.log('Error exists');
$('.validate').attr('style', "border-radius: 5px; border:#FF0000 1px solid;");
$('.validate').val('enter a value');
}
});
</head>
<body>
<form action="" method="post" id="submit_form">
<div>
<input class="validate" type="text" name="Name"/>
</div>
<input type="submit" value="Submit">
</form>
</body>
</html>
So by the above code the value "enter a value"
is updating in the field, but the field is not highlighting
所以通过上面的代码"enter a value"
,该字段中的值正在更新,但该字段没有突出显示
Also when i checked whether the style attribute has added to input.. and yes it was added successfully but why the field is not highlighting
此外,当我检查样式属性是否已添加到输入时.. 是的,它已成功添加,但为什么该字段未突出显示
回答by prabu
try this
尝试这个
$('.validate').css({ "border": '#FF0000 1px solid'});
by replacing
通过替换
$('.validate').attr('style', "border-radius: 5px; border:#FF0000 1px solid;");