关于(javascript) "if"关键字的一个疑惑的地方
一直以来对if(obj)的用法有点疑惑,不知道如果obj是一个对象的时候(而不是简单的true/false),该怎么执行。在什么情况下该为true,什么情况下又该为false.
通过下面的小测试,了解到,当obj="",obj=undefined,obj=null,obj=NaN 的时候返回false,obj不为空的时候则返回true。
var obj ;//undefined
if(obj)alert('0:init');
obj = "";//\0
if(!obj)alert('1:\"\"');
obj = undefined;//undefined
if(!obj)alert('2:undefined');
obj = null;
if(!obj)alert("3:null");
obj = false ;
if(!obj)alert("4:false");
obj = true ;
if(!obj)alert("5:true");
obj = "string";
if(!obj)alert("6:string");
obj = NaN;
if(!obj)alert("7:NaN");
执行的结果:
1:""
2:undefined
3:null
4:fasel
7:NaN
当用var 定义一个变量的时候,如果不初始化,则默认值是undefined。
相关文档:
RegExp对象(至今为止我看到过的最通俗易懂和深入的正则表达式教程)
JavaScript提供了一个RegExp对象来完成有关正则表达式的操作和功能,每一条正则表达式模式对应一个RegExp实例。有两种方式可以创建RegExp对象的实例。
使用RegExp的显式构造函数,语法为:new RegExp("pattern"[,"flag ......
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)> <td>no </table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy="return false;" oncut="re ......
1.对于数组,我们可以自己写一个indexOf()方法:
[].indexOf || (Array.prototype.indexOf = function(v){
for(var i = this.length;i-- && this[i] !== v;);
return i; });
使用: var array = new Array();
array = ...;
if(array.ind ......
第一步:在IE的“Internet设置”中选择“高级”——“安全”——“启用集成windows身份验证”。
第二步:在需要调试的页面的脚本中加上debugger; 然后运行这个页面,就会在这里停下来
例如:
function BtnSubmit_Click()
{
var aaa;
aaa='aaa';
debugg ......
演示地址: http://www.wowo-design.com/view/51_01/index.htm
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>css菜单演示</title>
<style type="text/css">
<!--
*{margin:0;padding:0;border:0;}
body {
......