美文网首页
jQuery 面试问题及答案

jQuery 面试问题及答案

作者: 五四青年_4e7d | 来源:发表于2020-02-13 16:01 被阅读0次

window.onload和document.ready的区别?

$(function(){}) 和 $(document).ready(function(){}),
这两个方法的效果都是一样的,
document.ready 和 window.onload 的区别是:
document.ready方法在DOM树加载完成后就会执行,
而window.onload是在页面资源(比如图片和媒体资源,
它们的加载速度远慢于DOM的加载速度)
加载完成之后才执行。也就是说$(document).ready要比window.onload先执行。

jquery中$each和原生的forEach方法区别?

foreach是js的原生方法;each是jquery的方法;
foreach只能循环遍历数组;each不仅能循环遍历数组;还能循环遍历jquery的伪数组

jquery的链式编程原理(那些方法不支持链式操作):

jquery最后都会return一个this,这个this就是当前元素的jquery对象
$(this).siblings("li[class!=header]").hide().next().show("fast");
不支持链式操作的:$.html()   $.text()   $.trim()   $.each

jquery常见方法汇总:

常用方法索引:

1.serialize()
2.text()    html()    val()
3.css()
4.get()        非ajax用法
5.parent()    children()    parents()    find()
6.eq()    siblings()    index()
7.height()    width()
8.addClass()    removeClass()    hasClass()   
9.toggle()    toggleClass()
10.show()    hide()
11.trim()
12.slideUp()    slideDown()    slideToggle()
13.attr()
14.add()    remove()    append()    appendTo()    prepend()    prependTo()
15.on()    事件委托
16.extend()
17.next()    nextAll()    nextUntil()
18.each()   
19.load()
20.get()    post()    ajax()
21.trigger()

相关文章

网友评论

      本文标题:jQuery 面试问题及答案

      本文链接:https://www.haomeiwen.com/subject/mmtlfhtx.html