Javascript-If和or语句-IE未定义
Javascript - If and or statements - IE Undefined
我很困惑为什么这不起作用。。。
在chrome中,当我单击运行该脚本的按钮时,弹出的文本框是空的,所以我检查长度是否大于0….
在IE中,它将其填充为未定义,所以我想我可以检查值并说if!=未定义。。。
if (strTemp.length > 0) {
if (strTemp.value != "undefined") {
printLabels(strCarrier, strTemp);
} else {
alert('You wont get labels until you tell us why...');
}
}
else {
alert('You wont get labels until you tell us why...');
}
有人知道我做错了什么吗?
如果值是undefined
,则它不是字符串。您应该检查if (strTemp.value != undefined)
。
参见MDN上的undefined
。
未定义是一种数据类型,而不是字符串值。如果你想与字符串进行比较,请尝试使用以下方法:
if (typeof strTemp.value === "undefined") {
alert("strTemp.val is undefined");
}
if (strTemp && strTemp.value) {
printLabels(strCarrier, strTemp);
} else {
alert('You wont get labels until you tell us why...');
}
以防万一有人想知道。。。这就是我最终解决问题的方式…
if (strTemp.length > 1) {
if ((strTemp == "undefined") || (strTemp == "")){
alert('You wont get labels until you tell us why...');
}else{
printLabels(strCarrier, strTemp);
}
}else{
if ((strTemp == "undefined") || (strTemp == "")){
alert('You wont get labels until you tell us why...');
}else{
printLabels(strCarrier, strTemp);
}
}
相关文章:
- IE/Chrome中未定义的函数,但Firefox中没有
- 无法获取属性'字符串'的未定义或null引用IE 11 ASP.NET
- Javascript'元素'在ie中未定义,但在chrome和firefox中运行良好
- 浏览并选择用户硬盘驱动器中的文件在IE中未定义
- IE错误:无法设置属性'的值;样式':对象为null或未定义
- IE:无法获取属性'的值;clientWidth':对象为null或未定义
- 拖放文件时,dataTransfer.items属性在Firefox和IE中未定义,但在Chrome中未定义
- getElementsByTagName 为空或未定义,仅在 IE 中 - 并且仅在函数中的一个特定位置
- SharePoint 2013 Calendar getSelector 在 IE 中未定义
- “FormData”仅在IE中未定义
- “无法获取未定义或空引用的属性'getData'”在IE中,但不能在Chrome中获取
- 未捕获的类型错误:无法读取IE和Chrome Firefox中未定义的属性“文档”很好
- JavaScript函数仅在IE中未定义
- IE上未定义对象值
- IE 11上未定义鼠标事件属性
- '这'chrome中未定义,但在IE中有效
- javascript:var仅在IE中未定义
- js变量'未定义'在IE中(值由ajax响应设置)
- FireFox”;窗口_laq未定义”;错误适用于Chrome和IE
- Javascript-If和or语句-IE未定义