javascript - unable to change the input background based on condition
问题描述
here below is my JSON data
data = {
name: 'paul',
author: '',
country: '',
id: 7465
};
here by using the above data, I am displaying the input and label
<label class="inline-label" for="{{data.name}}">{{data.name}}</label>
for input
<input id="{{data.name}}" type="{{data.details.type}}" style=" border-radius:0;" class="form-control error">
here my issue is
- I unable to display the input background color based on condition when the input value is empty only for selected one I have other input also it is based on other than I don't want to change
below is the code I have tried
if (data['author'] === '') {
$('.error').css('background-color', '#fff');
$('.error')
.filter(function() {
return $.trim(this.value) === '';
})
.css('border-bottom:', '1px solid #FF0000 !important');
} else {
$('.error').css({ 'background-color': 'green' });
}
解决方案
你可以使用这样的东西,它不包括 jquery
.white-background{
background-color
}
`<input id="{{data.name}}" [class.white-background]="!data.author" type="`{{data.details.type}}" style=" border-radius:0;" class="form-control error">
推荐阅读
- java - 有没有办法验证 GCP 资源名称而不尝试创建它?
- c# - MonoGame 中的字体太尖锐
- flutter - 为什么 FlatButton 占用的空间多于应有的空间?
- discord.js - DM 频道中的 awaitMessages
- android - 开始购买流程时,应用程序强制将方向横向更改为纵向
- c++ - 如何像二维数组一样使用 natvis 可视化列顺序矩阵
- c# - 全局错误捕获以防止运行时异常导致程序崩溃
- python - 在 Python 中加速打字自动化
- java - Fragments 在发布应用程序 android 中自动开始重新加载
- c++ - 为什么我从随机数中得到相同的答案?