我想检查该值是否为空或一个空格,因此我编写了一段代码
var OccLocation = document.getElementById("HdnOccLocation");
if (OccLocation.value != " " && OccLocation.value != "") {
alert("not empty");
}
<input type="hidden" id="HdnOccLocation" name="HdnOccLocation" value="" style="position:absolute;height:20px;color:#000000;text-align:left;font-size:12px;font-style:normal;width:26px;background-color:#00cccc;left:800px;font-weight:normal;top:220px;" class="textClass"
/>
最佳答案
您可以按如下方式更新您的状况。
var OccLocation = document.getElementById("HdnOccLocation");
if (OccLocation.value.trim() == "") {
alert("empty");
}
如果您想在 OccLocation
不为空时收到警报:
var OccLocation = document.getElementById("HdnOccLocation");
if (OccLocation.value.trim() != "") {
alert("not empty");
}
关于javascript - 为什么我不能在 javascript 中使用 && 来表示非空白和非空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53207061/