简体   繁体   English

如何清除和固定边框

[英]How to clear and rest solid border

I've added a red border to my input boxes on error generated during form validation 在表单验证期间生成的错误中,我向输入框添加了红色边框

 <input id="cardnumber" />

The border is set to red in my javascript using: 使用以下命令在我的JavaScript中将边框设置为红色:

 $(cardnumber).css({ "border":' solid #ff0000'})

Now I would like to clear the solid border when the user resolves the error: 现在,当用户解决错误时,我想清除实线边框:

I tried: 我试过了:

 $(cardnumber).css({"outline":'none'})
 $(cardnumber).css({"outline":'0'})

None of of the above works. 以上都不是。

Whats the correct css to reset the border? 什么是重置边框的正确CSS?

Set the border to none : 将边框设置为none

$(cardnumber).css({"border-color":'black'});

But rather than changing CSS explicitly, it's generally better to use classes and put the styles in your CSS file. 但是,与其显式地更改CSS相比,使用类并将样式放在CSS文件中通常更好。

Try border: none; 尝试border: none;

Outline is not the same as border 轮廓与边框不同

Keep the value of the border css before the error in a variable and reapply after: 将边框css的值保留在错误之前的变量中,然后在以下位置重新应用:

$borderbefore = document.getElementById('cardnumber').style.border;
...
//error
 $(cardnumber).css({ "border":' solid #ff0000'})
...
//correction
document.getElementById('cardnumber').style.border = $borderbefore;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM