$(function(){ } 这是jquery里的,是当文档载入完毕就执行,的意思.
$(function(){
$("#treeDiv1").load("composer.jsp?type=list");
$("#treeDiv2").load("composer.jsp?type=list2");
});
这个就是当文档加载完成,就执行
$("#treeDiv1").load("composer.jsp?type=list");
$("#treeDiv2").load("composer.jsp?type=list2");
这两个语句,
其实是跟较早的版本的$(document).ready(function(){...... }) 是一样的
我这里再简要说明下,
(function($){...})(jquery);
和
a=function($){...};
a(jquery);
等价.
这种写法就是为了让匿名函数立即执行.
您也许已经注意到在我们的实例中的所有 jQuery 函数位于一个 document ready 函数中:
$(document).ready(function(){
---jQuery functions go here ----
});
这是为了防止文档在完全加载(就绪)之前运行 jQuery 代码。
当按钮的点击事件被触发时会调用一个函数:
$("button").click(function(){..some code... } )
Correspondent to windows event function
toggle() 方法来切换 hide() 和 show()方法。
jQuery Callback 函数
实例
$("button").click(function(){$("p").hide(1000); });
由于 JavaScript 语句(指令)是逐一执行的 - 按照次序,动画之后的语句可能会产生错误或页面冲突,因为动画还没有完成。
为了避免这个情况,您可以以参数的形式添加 Callback 函数。
jQueryCallback 函数
当动画 100% 完成后,即调用 Callback 函数。
典型的语法:
$(selector).hide(speed,callback);
callback参数是一个在 hide 操作完成后被执行的函数。
错误(没有 callback)
$("p").hide(1000);alert("The paragraph is now hidden");
正确(有 callback)
$("p").hide(1000,function(){alert("The paragraph is now hidden"); });结论:如果您希望在一个涉及动画的函数之后来执行语句,请使用 callback 函数。
The core reason isthat JS use multithread
默认地,所有 HTML 元素都有一个静态位置,且无法移动。
如需对位置进行操作,要记得首先把元素的 CSS position 属性设置为 relative、fixed 或 absolute!
可以用 animate() 方法来操作所有 CSS 属性吗?
是的,几乎可以!不过,需要记住一件重要的事情:当使用 animate() 时,必须使用 Camel 标记法书写所有的属性名,比如,必须使用 paddingLeft 而不是 padding-left,使用 marginRight 而不是 margin-right,等等。
同时,色彩动画并不包含在核心jQuery 库中。
如果需要生成颜色动画,您需要从jQuery.com 下载 Color Animations 插件。
vartxt1="<p>Text.</p>"; // 以HTML 创建新元素
vartxt2=$("<p></p>").text("Text."); // 以 jQuery 创建新元素
vartxt3=document.createElement("p"); // 以 DOM 创建新元素
txt3.innerHTML="Text.";
Jquery
Selectelement
Event
(ready,click, dbclick, mouseover, focus)
Show/hide
(hide,show, toggle)
Fide
(fadein,fadeout, fadetoggle, fadeto)
Slidemove
(slidedown,slideup, slidetoggle)
Animate
(modify css)
Modifytext html
(text(),html(), value() param: 1 get 2 set 3 callback)
(append(),prepend(), before(), after())
Css
a.fn.typewriter= function(speed) {
Create anew jquery method typewriter
HTMLDOM setInterval(code,millisec[,"lang"])
输出每个 li 元素的文本, follow the order in html, not synchronous
$("button").click(function(){
$("li").each(function(){
alert($(this).text())
});
});
each()方法规定为每个匹配元素规定运行的函数。
Typewriter html contains the /n, it will cause the multiple pause during the start and enter anew line
functionPeople(name)
{
this.name=name;
//对象方法
this.Introduce=function(){
alert("Myname is "+this.name);
}
}
//类方法
People.Run=function(){
alert("Ican run");
}
//原型方法
People.prototype.IntroduceChinese=function(){
alert("我的名字是"+this.name);
}
//测试
varp1=new People("Windking");
p1.Introduce();
People.Run();
p1.IntroduceChinese();
3 obj1.func.call(obj)方法
意思是将obj看成obj1,调用func方法
A.prototype= new B();
理解prototype不应把它和继承混淆。A的prototype为B的一个实例,可以理解A将B中的方法和属性全部克隆了一遍。A能使用B的方法和属性。这里强调的是克隆而不是继承。可以出现这种情况:A的prototype是B的实例,同时B的prototype也是A的实例。
实验证明:函数运行时会先去本体的函数中去找,如果找到则运行,找不到则去prototype中寻找函数