其他分享
首页 > 其他分享> > 四、$jQuery

四、$jQuery

作者:互联网

1、你觉得jQuery或zepto源码有哪些写的好的地方

 (function( window, undefined ) {

         //用一个函数域包起来,就是所谓的沙箱

         //在这里边var定义的变量,属于这个函数域内的局部变量,避免污染全局

         //把当前沙箱需要的外部变量通过函数参数引入进来

         //只要保证参数对内提供的接口的一致性,你还可以随意替换传进来的这个参数

        window.jQuery = window.$ = jQuery;

    })( window );

2、jQuery 的实现原理?

3、jQuery.fninit 方法返回的 this 指的是什么对象? 为什么要返回 this

4、jQuery.extend 与 jQuery.fn.extend 的区别?

$.extend({
  min: function(a, b) { return a < b ? a : b; },
  max: function(a, b) { return a > b ? a : b; }
});
$.min(2,3); //  2
$.max(4,5); //  5
var settings = {validate:false, limit:5};
var options = {validate:true, name:"bar"};
$.extend(settings, options);  // 注意:不支持第一个参数传 false
// settings == {validate:true, limit:5, name:"bar"}
$.fn.extend({
   alertValue: function() {
      $(this).click(function(){
        alert($(this).val());
      });
   }
});

$("#email").alertValue();

5、jQuery 的属性拷贝(extend)的实现原理是什么,如何实现深拷贝?

6、jQuery 的队列是如何实现的?队列可以用在哪些地方?

var func1 = function(){alert('事件1');}
var func2 = function(){alert('事件2');}
var func3 = function(){alert('事件3');}
var func4 = function(){alert('事件4');}

// 入栈队列事件
$('#box').queue("queue1", func1);  // push func1 to queue1
$('#box').queue("queue1", func2);  // push func2 to queue1

// 替换队列事件
$('#box').queue("queue1", []);  // delete queue1 with empty array
$('#box').queue("queue1", [func3, func4]);  // replace queue1

// 获取队列事件(返回一个函数数组)
$('#box').queue("queue1");  // [func3(), func4()]

// 出栈队列事件并执行
$('#box').dequeue("queue1"); // return func3 and do func3
$('#box').dequeue("queue1"); // return func4 and do func4

// 清空整个队列
$('#box').clearQueue("queue1"); // delete queue1 with clearQueue

7、jQuery 中的 bind(), live(), delegate(), on()的区别?

8、是否知道自定义事件? jQuery 里的 fire 函数是什么意思,什么时候用?

document.createEvent(type); // 创建事件
  event.initEvent(eventType, canBubble, prevent); // 初始化事件
  target.addEventListener('dataavailable', handler, false); // 监听事件
  target.dispatchEvent(e);  // 触发事件

9、jQuery 通过哪个方法和 Sizzle 选择器结合的?

10、jQuery 中如何将数组转化为 JSON 字符串,然后再转化回来?

// 通过原生 JSON.stringify/JSON.parse 扩展 jQuery 实现
 $.array2json = function(array) {
    return JSON.stringify(array);
 }

 $.json2array = function(array) {
    // $.parseJSON(array); // 3.0 开始,已过时
    return JSON.parse(array);
 }

 // 调用
 var json = $.array2json(['a', 'b', 'c']);
 var array = $.json2array(json);

11、jQuery 一个对象可以同时绑定多个事件,这是如何实现的?

  $("#btn").on("mouseover mouseout", func);

  $("#btn").on({
      mouseover: func1,
      mouseout: func2,
      click: func3
  });

12、针对 jQuery 的优化方法?

13、jQuery 的 slideUp 动画,当鼠标快速连续触发, 动画会滞后反复执行,该如何处理呢?

14、jQuery UI 如何自定义组件?

15、jQuery 与 jQuery UI、jQuery Mobile 区别?

16、jQuery 和 Zepto 的区别? 各自的使用场景?

17、jQuery对象的特点

标签:jQuery,function,extend,queue1,window,事件
来源: https://www.cnblogs.com/Strugglinggirl/p/11058366.html