javascript - 高亮文本字段的逻辑操作
问题描述
所以我在这里有一个场景,需要根据使用 javascript/html 的条件突出显示一个字段
假设如果 A 和 B 字段为空,则需要 C 或 D 字段来提交请求,反之亦然。
解决方案
我不太明白你需要什么,你能更具体一点吗?你有什么尝试,你能发布一些你的代码,让我们了解你真正需要什么吗?但据我所知,您希望字段 A 和 B 具有值 OR C 和 D(反之亦然??),但如果 A 和 B 没有任何值,则 C 或 D 必须继续,对吗?无论如何,那个 .js 是可以理解的,所以你可以按照你想要的方式配置它..
<!DOCTYPE html>
<html>
<body>
<input id="A" type="text">
<input id="B" type="text">
<input id="C" type="text">
<input id="D" type="text">
<button type="button" onclick="myFunction()">Submit</button>
<p id="demo"></p>
<script>
function myFunction() {
var Aa, Bb, Cc, Dd;
Aa = document.getElementById('A').value
Bb = document.getElementById('B').value
Cc = document.getElementById('C').value
Dd = document.getElementById('D').value
//if A and B fields has values = OK
if(Aa !== null && Aa !== '' && Bb !== null && Bb !== '') {
text = "Input OK";
}
else if (Cc !== null && Cc !== '' || Dd !== null && Dd !== ''){
text = "Values A and B are empy, but C OR D has values";
}
else{
text = "NOT OK: Insert values into A AND B or C OR D"
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
推荐阅读
- javascript - boundingSphere 为空 - TextGeometry,ThreeJS
- css - 仅更改内容辅助字体大小
- spring-data-jpa - 创建名称为“entityManagerFactory”的 bean 时出错,javaxb 或休眠依赖项未修复
- php - yii2 将 AJAX 表单转换为不同的操作 url
- google-cast - Android Sender Seekbar 状态不准确
- class - 错误:将“const xxx”作为“this”参数传递会丢弃限定符
- javascript - Python、Javascript 和 C++ 中的全局变量
- node.js - 为什么我会收到“错误:找不到模块‘ejs’”
- python - qmlscene 和 Python 之间的不同屏幕:工具栏
- excel - Excel 需要查找连续 5 个数字中有 3 个大于或等于 0.45 的情况