$.type()的用法

来源:互联网 发布:自学编程网站有哪些 编辑:程序博客网 时间:2024/06/05 16:46

jquery中$是对jQuery类的简写,$.type等价于jQuery.type

js代码

function Test1(cfg){var list = new Array();if($.type(cfg)=='array'){console.log('我是数组');list = list.concat(cfg);}else if(jQuery.type(cfg)=='object'){console.log('我是对象');list.push(cfg);}else if($.type(cfg)=='boolean'){console.log('我是布尔值');list.push(cfg);}else if(jQuery.type(cfg)=='number'){console.log('我是数字值');list.push(cfg);}else if($.type(cfg)=='string'){console.log('我是字符串');list.push(cfg);}else if(jQuery.type(cfg)=='function'){console.log('我是函数');list.push(cfg);}else if($.type(cfg)=='error'){console.log('我是错误');list.push(cfg);}else if(jQuery.type(cfg)=='date'){console.log('我是日期');list.push(cfg);}else if($.type(cfg)=='regexp'){console.log('我是正则表达式');list.push(cfg);}}
html代码

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->  <script type="text/javascript" src="jquery-1.7.js"></script>  <script type="text/javascript" src="jquery-1.7.min.js"></script>  <script type="text/javascript" src="my.js"></script>   <script type="text/javascript">  $(function(){Test1([{id : '1',name : '张三',params : {age : '20',tell : '1234567'}}]);Test1({id : '1',name : '张三',params : {age : '20',tell : '1234567'}});Test1(true);Test1(12);Test1("name");Test1(function(){});Test1(new Error());Test1(new Date());Test1(/test/);var br = $("<br/>");$(".myspan").append(br);  })  </script>  </head>    <body>  </body></html>
输出




0 0