关于(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。
相关文档:
//服务器弹出对话框
if (lcSID == "1" && (txtNsp.Text.Trim() != lcNewspaper || Convert.ToDateTime(txtNspdate.Text.Trim()) != Convert.ToDateTime(lcNspdate)))
{
string lcJs = "v ......
Event属性和方法:
1. type:事件的类型,如onlick中的click;
2. srcElement/target:事件源,就是发生事件的元素;
3. button:声明被按下的鼠标键,整数,1代表左键,2代表右键,4代表中键,如果按下多个键,酒把这些值加起来,所以3就代表左右键同时按下;(firefox中 0代表左键,1代表中间键,2代表右键) ......
此例子是javascript高级程序设计里的
放出来心备以后使用。上代码。
<html>
<head>
<title>Table Sort Example</title>
<mce:script type="text/javascript"><!--
function convert(sValue, sDataType) {
swi ......
在页面上回车后,不做任何动作。
<script type="text/javascript">
function document.onkeydown()
{
if(event.keyCode ==   ......