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

时间:2021-05-07 19:40:43

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;
}

1 个解决方案

#1


0  

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,这将使动态更容易动作。

#1


0  

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,这将使动态更容易动作。