关于jquery部分知识点

1.jquery如果需要匹配包含文本的元素使用什么方法?
<div>John Resig</div>
$("div:contains('John')")
[<div>John Resig</div>]
2.juqery中怎样快速选择第一个元素?
:first或者eq(0)
3.jquery有哪些文档处理的方法?
(来源于jquery文档)内外部插入/包裹/替换/删除/复制
内部插入
append(content|fn)
appendTo(content)
prepend(content|fn)
prependTo(content)
外部插入
after(content|fn)
before(content|fn)
insertAfter(content)
insertBefore(content)
包裹
wrap(html|ele|fn)
unwrap()
wrapAll(html|ele)
wrapInner(html|ele|fn)
替换
replaceWith(content|fn)
replaceAll(selector)
删除
empty()
remove([expr])
detach([expr])
复制
clone([Even[,deepEven]])
4.怎么在一个指定元素后添加内容?
我自己会混淆的地方(after和insertAfter各自位置的放置)
after的使用(在...之后插入content)
HTML 代码:
<p>I would like to say: </p>
jQuery 代码:
$("p").after("<b>Hello</b>");  //在p之后插入<b></b>  
结果:
<p>I would like to say: </p><b>Hello</b>

insertAfter的使用(content插入在...之后)
HTML 代码:
<p>I would like to say: </p><div id="foo">Hello</div>
jQuery 代码:
$("p").insertAfter("#foo");   //p插入在id为foo的标签之后
结果:
<div id="foo">Hello</div><p>I would like to say: </p>
5.在jquery中如何使用一个表达式来检查当前选择元素的集合
使用is(expr)来实现,如果这个表达式失败,则返回false。
6.在jquery中,想要给第一个指定元素添加样式用css("name")
7.jquery中获取当前窗口的宽度值用
$(window).width(); //浏览器当前窗口可视区域宽度。
8.jquery如何处理缓存?
方法一:使用$.post()方法来获取数据。
方法二:使用$.get()方法获取数据是需要设置时间戳。
方法三:使用$.ajax方法来获取数据,设置cache:false。
发布了12 篇原创文章 · 获赞 9 · 访问量 192

猜你喜欢

转载自blog.csdn.net/weixin_43279985/article/details/103848902
今日推荐