This should be the entry level JS article, we JS determine whether the variable is an empty example of a brief introduction.
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd" >
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/>
<TITLE>JS determine whether the variable is empty </title>
<script>
function S () {
var Tt=document.getelementbyid ("DW"). Value;
Alert (TT);
if (Tt==null | | tt== "") {
Alert ("Input, can not be empty Oh");
}
else{
Alert (TT);
}
return false;
}
</script>
</head>
<body>
<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<label for= "TextField" ></label>
<input type= "text" name= "DW" id= "DW"/>
<input type= "Submit" name= "button" id= "button" value= "Submit" onclick= "Web effects: return s ();"/>
</form>
</body>
</html>
That affirmative variable is not empty Ah, teach you a way that you write:
function S () {
var Tt=document.getelementbyid ("DW"). Value;
SSSSSS ()//program run this will be the error, click Debugging, with Debugging tools to follow up to see what the situation
if (tt!=null) {
Alert ("Bukong");
}
else{
Alert ("Kong");
}
}
Also, attach a method to determine whether it is empty:
var isnull = function (obj)
{
Try{return Obj==0?false:!obj}catch (e) {return false;}
}