第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

不要過(guò)度依賴(lài)JQuery(三)

標(biāo)簽:
JQuery

在这里先拜个年,祝大家新年快乐,阖家幸福,步步高升!

回归正题,在不要过度依赖JQuery(一)

失去焦点

$('#test').blur();
$('#test').blur(function(){});   
function blur(elem, fn) {    
  if(fn && typeof fn === 'function') {    
    addEvent(elem, 'blur', fn);    
  } else {    
    elem.blur();    
  }   
}    

blur(t, function(){});

实时监控

$('#test').on('input propertychange', fn);function inputChange(dom, fn, capture) {   
  capture = capture || false;   
  addEvent(dom, 'input', fn, capture);
  addEvent(dom, 'propertychange', fn, capture);   
}

inputChange(t, function(){});

2、判断类型

判断类型

$.type(obj);Object.prototype.toString.call(obj).replace(/^\[object (.+)\]$/, '$1').toLowerCase();

判断是否为一个函数

$.isFunction(fn)function isFunction(fn){  return typeof fn === 'function';
}

判断是否为数字

$.isNumeric(num);function isNumber(num) {  var type = typeof num;  return ( type === 'number' || type === 'string') && 
      !isNaN( num - parseFloat( num ) );
}

判断是否为数组

$.isArray(obj);function isArray(obj) {  if( Array.isArray ) {    return Array.isArray(obj);
  } else {    return Object.prototype.toString.call(obj) === '[object Array]';
  }
}

3、时间

获取当前时间

$.now()new Date().getTime();/* 更简单 */+new Date();

4、改变上下文(this)

$.proxy(fn, context);

fn.bind(context);

5、空函数

创建一个空函数

var fn = $.noop();var fn = function() {}

6、数组

合并数组

$.merge(arr1, arr2)function (arr1, arr2) {  return arr1.concat(arr2);
}

类数组对象转换成数组

var divs = document.querySelectorAll('div');var arr = $.makeArray(divs);var arr = Array.prototype.slice.call(divs);// ES6 var arr = Array.from(divs)

7、Iframe

获取iframe的document

$('#iframe').contents();var iframe = document.getElementById('iframe');
iframe.contentDocument;

8、元素包含关系

检查一个DOM元素是另一个DOM元素的后代

$.contains(parent, child);function contains(root, el) { 
  /* Chrome / Firefox */  
  if (root.compareDocumentPosition) {  
    return root === el || !!(root.compareDocumentPosition(el) & 16);  
  } 
  /* IE */
  if (root.contains && el.nodeType === 1){   
    return root.contains(el) && root !== el;   
  }   
  while ((el = el.parentNode)) {  
    if (el === root) { return true; }  
    return false;   
  }
}

9、scroll

设置/获取window滚动位置

/*获取*/$(window).scrollTop();

(document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop/*设置*/$(window).scrollTop(10);

(document.documentElement && document.documentElement.scrollTop = 10) || document.body.scrollTop = 10;

设置某个元素滚动位置

$('#test').scrollTop(10);var t = document.getElementById('test');

t.scrollTop = 10;

注意:别加单位!

10、节点

获取元素的最近的祖先定位(position非static)元素

$('#test').offsetParent();var t = document.getElementById('test');
t.offsetParent;

到这里,《不要过度依赖JQuery》系列就告一段落了!

原文链接:不要过度依赖JQuery(三)

如有错误或建议,欢迎在下方评论区留言!



作者:TGCode
链接:https://www.jianshu.com/p/526cd16f68a7


點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫(xiě)下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶(hù)
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消