jQuery核心方法

1、$(document.body).css( "background", "black" );

2、$(myForm.elements).hide();隐藏表单所有元素。

3、$("<input type='checkbox'>").appendTo("body");将动态input标签追加到body

4、$(document).ready(function (){ });===》简写:$(function (){ 文档就绪 });

5、$.holdReady();允许调用者延迟jQuery的ready事件
eg:延迟就绪事件直到已加载插件。
$.holdReady(true);
$.getScript("myplugin.js", function() {
$.holdReady(false);
});

6、each(callback);,每次执行传递进来的函数时,函数中的this关键字都指向一个不同的DOM元素(每次都是一个不同的匹配元素)。
eg:
$("img").each(function(i){
this.src = "test" + i + ".jpg";
});

可使用return跳出each循环
eg:
$("button").click(function () {
$("div").each(function (index, domEle) {
// domEle == this
$(domEle).css("backgroundColor", "yellow");
if ($(this).is("#stop")) {
$("span").text("Stopped at div index #" + index);
return false;
}
});
});

7、size(); jQuery 对象中元素的个数。
8、length(); jQuery 对象中元素的个数。

9、selector; 确定查询的选择器(返回你用什么选择器来找到这个元素的)
10、context; 返回传给jQuery()的原始的DOM节点内容.
11、get(index):返回指定的第几个元素
eg:$("img").get(0); 返回第0张图片

12、使用DOM Core来获取某元素的指定属性:element.getAttribute("属性值")

eg.

<img src="demo3.html" id="pic"/>
alert(document.getElementById('pic').getAttribute("src"))

结果:demo3.html
没有人能一路单纯到底,但是要记住,别忘了最初的自己!
原文地址:https://www.cnblogs.com/LindaBlog/p/9719251.html