简体   繁体   English

如何根据另一个字段中的值将字段边框颜色更改为红色?

[英]How do I change the field border color to red based on a value in another field?

I'm trying to compare two fields, and if the value in one field is greater than 3, I'm trying to make the other field required and have a red border to signal the user to input a value. 我正在尝试比较两个字段,并且如果一个字段中的值大于3,则试图使另一个字段成为必需,并用红色边框表示用户输入值。

Here's my existing code, which I got to work to make the other field required - but I'm not sure how to add the border color in. All help is appreciated! 这是我现有的代码,必须使用该代码才能使其他字段成为必需-但我不确定如何添加边框颜色。感谢所有帮助!

var v = this.getField("DISP_CODE_1").value;

if(v > 3){
event.target.required = true;
}
else {
event.target.required = false;
}

You can do something like this: 您可以执行以下操作:

var v = this.getField("DISP_CODE_1").value;

if(v > 3){
    event.target.required = true;
    event.target.className += " " + classNameWithRedBorder;
}
else {
    event.target.required = false;
}

With JQuery, you could use .addClass() and .removeClass() to add/remove the css which would make it easier to act dynamically. 使用JQuery,您可以使用.addClass()和.removeClass()来添加/删除css,这将使动态操作更加容易。

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

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