if(一个变量),没有> < !=这些半短逻辑, 什么时候为真 什么时候为假?
解决方案 »
- 在线等待求教——用js操纵iframe的页面跳转?
- 求解,JS在Firefox中的透明效果
- 请问大家一个投票的问题
- JS里面如何取得当前正在执行的FUNCTION的名字
- 急!!请教如何用jquery获取表格里通过for循环显示出的一个特定的数据??可能提问标题大家没搞懂,请大家进来看看,里面有问题的代码,谢谢!!
- 子框架页面要打开非模态窗口的问题
- 买了JSP编程小技巧集锦,现在转送,需要的请进!
- 刚学asp 几个小问题请教各位
- 送分:从文本框和选择框的数值判断结果!!
- javascript 如何实现 截取URL中的参数后.批量赋值
- 怎样用jquery使输入框在失去焦点时,使用label的属性值
- -------------------JS拼接和分割方法-----------------------
1为false
空值为false
非空值true
var r = "";
window.onload = function () {
var a;
wLine(((a) ? "true " : "false ") + typeof (a)); //false a==undefined
wLine(((a=null) ? "true " : "false ") + typeof (a)); //false a==null
wLine(((a = -0) ? "true " : "false ") + typeof (a)); //false a==0
wLine(((a = -0.000000000001) ? "true " : "false ") + typeof (a)); //true a!=0
wLine(((a = "") ? "true " : "false ") + typeof (a)); //false a==""
wLine(((a = " ") ? "true " : "false ") + typeof (a)); //true a==" " 空格
wLine(((a = function () { return false; }) ? "true " : "false ") + typeof (a)); //true a==function
wLine(((a =( function () { return false; }))() ? "true " : "false ") + typeof (a)); //false a==function
}
function wLine(val) {
var f = document.forms[0];
if(f)f.innerHTML+=val+"<hr/>";
else alert(val);
}
</script>
if(a) 只要a!=0 ; a!=null;a!=undefined;a!=""的情况下基本就成立了。
非真值:null undefined '' 0 false
真值:任意对象、任意非0数字、任意非空字符串、trueif(a){}表示如果a为真值就执行。