jQuery 面试题
2019-03-16 本文已影响0人
岚平果
选择器
- 有哪些选择器
基本选择器
#id
.class
div
*
session1, session2
过滤选择器
:lt(index)
:gt(index)
:eq(index)
:even
:odd
属性选择器
[attribute=value]
表单选择器
[:input]
[:text]
[:password]
[:radio]
[:checkbox]
[:submit]
[:image]
[:reset]
[:button]
[:file]
- 选取ul里前面三个li
$('ul li:lt(3)')
- 选ul里面偶数的li,给这些li加上红色的背景色,然后又选取ul给ul设置字体大小18px
- 选择一个div元素的祖辈元素class=“parent”的元素
- DOM元素如何转jquery元素;jquery元素如何转DOM元素
DOM操作
- 给ul插入一个li,内容为helloworld
- 清空ul里面所有的li
- 删除ul
动效
$('div').stop().animate({
left: '70px'
}, 400)
事件
- 事件绑定
$('div').bind('mousedown', fn)
$('div').on('mousedown', fn)
- 事件解绑
$('div').unbind('mousedown', fn)
$('div').off('mousedown', fn)
- 事件委托
$('ul').on('mousedown', 'li', fn)
- 事件模拟
$('div').on('mousedown', fn)
$('div').trigger('mousedown')
- 事件对象
$('div').
. 阻止事件冒泡
e.stopPropagation();
. 阻止事件默认行为
e.preventDefault();
. 获取点击事件的相对浏览器的坐标
e.target.clientX
e.target.clientY
- 事件命名空间有没有了解过
ajax
- ajax常用参数说明
$.ajax({
url,
type,
data,
dataType,
beforeSend,
success,
error
})
- ajax请求成功了,有数据了,但是不走success方法,是什么原因