jQuery入口函数测试
2021/6/5 18:24:14
本文主要是介绍jQuery入口函数测试,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<script src="js/jquery-1.12.4.js"></script> <script> window.onload = function (ev) { /* jQ入口函数传入不同参数得到的实例 1.传入 '' null undefined NaN 0 false 2.传入html片段 3.传入选择器 4.传入数组 5.传入伪数组 6.传入对象 7.传入DOM元素 8.传入基本数据类型 */ // 1.传入 '' null undefined NaN 0 false // 会返回一个空的jQuery console.log($()); console.log($('')); console.log($(null)); console.log($(undefined)); console.log($(NaN)); console.log($(0)); console.log($(false)); // 2.传入html片段 // 会将创建好的DOM元素存储到jQuery对象中返回 console.log($('<p>1</p><p>2</p><p>3</p>')); // 3.传入选择器 // 会将找到的所有元素存储到jQuery对象中返回 console.log($('li')); // 4.传入数组 // 将数组中存储的元素一次存储到jQuery对象中并返回 console.log($([1, 2, 3, 4, 5, 6])); // 5.传入伪数组 // 将数组中存储的元素一次存储到jQuery对象中并返回 var likeArr = {0:"lnj", 1:"33", 2:"male", length:3}; console.log($(likeArr)); // 6.传入对象 // 会将传入的对象存储到jQuery对象中返回 function Person(){ } console.log($(new Person())); // 7.传入DOM元素 // 会将传入的Dom元素存储到jQuery对象中返回 console.log($(document.createElement('div'))); // 8.传入基本数据类型 console.log($(123)); console.log($(true)); /* 1.传入 '' null undefined NaN 0 false, 返回空的jQuery对象 2.字符串: 代码片段:会将创建好的DOM元素存储到jQuery对象中返回 选择器: 会将找到的所有元素存储到jQuery对象中返回 3.数组: 会将数组中存储的元素依次存储到jQuery对象中立返回 4.除上述类型以外的: 会将传入的数据存储到jQuery对象中返回 */ } </script>
这篇关于jQuery入口函数测试的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-06jquery对css样式(jquery中的css方法)-icode9专业技术文章分享
- 2023-05-27JQuery的认识和安装
- 2023-01-06JQuery应用技巧:如何定义 HTML 模板并使用 JQuery 进行加载-icode9专业技术文章分享
- 2022-09-29复习-jQuery
- 2022-09-04Python3项目初始化10-->前端基础jquery、ajax,sweetalert--更新用户改造
- 2022-08-30day 27 jquery
- 2022-08-29jQuery筛选器,bootstrap
- 2022-08-20JQuery事件绑定
- 2022-08-20JQuery案例
- 2022-08-07关于jQuery的学习