每天CookBook之JavaScript-004

  • 判断变量为非空字符串
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>003</title>
</head>
<body>
	
</body>
<script type="text/javascript">
unknownVariable = "test string";
if (((typeof unknownVariable != 'undefined' && unknownVariable) &&
    unknownVariable.length > 0) &&
    typeof unknownVariable.valueOf() == 'string'){
	console.log("非空字符串");
}
</script>
</html>
posted @ 2016-07-07 21:41  4Thing  阅读(92)  评论(0编辑  收藏  举报