javascript - 为什么我不能在 javascript 中使用 && 因为不是空白而不是空格
问题描述
我想检查值不是空白或一个空格所以我写了一个代码
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");
}
推荐阅读
- python - 如何在表单中使用 pythonmechanissoup 将文件上传到 ASP.net 站点
- html - UL 现在显示为编号列表
- python - conda 环境改变了哪个 conda
- reactjs - Redux 在解构时只提取一部分数据
- php - 我无法在 Codeigniter 中获取 stdClass 对象值
- linux - 一段时间后,当从 Windows SSH 到 linux 机器时,子进程(在分叉后创建)卡在 Windows 上
- python - Python产生清晰的输出
- jsf - 如何使用 faces-config 在同一页面上显示错误消息
- javascript - 修复 URL 以返回带有 JsonResult 的下拉列表项 - MVC- C#
- python - 元组字典