width : $(selector).width(200); //带参数设置,不带参数获取
innerHeight //只能获取:内边距+内容的高度
innerWidth //同上.........宽度
outerHeight
outerWidth //获取:左右内边距+内容+左右边框offset() 获取或设置元素相对于文档位置的方法
返回一个object,包含left和top属性,值是相对于document的位置。如果传入一个参数,则是对元素重新设置相对于document的位置。
传入参数必须包括:left和top属性。比如: {left:100,top:150}例如:$(selector).offset({left:100, top: 150});
position() 获取相对于其最近的定位的父元素的位置。
只能获取,不能设置。相对与其最近的定位元素返回一个object,包含left和top属性例如: $(selector).position();
元素的滚动
scrollLeft() 获取或者设置元素水平方向滚动的位置scrollTop() 获取或者设置窗口垂直方向的滚动的位置例如: $(selector).scrollLeft(100);
scroll() 事件触发或者绑定滚动事件
scroll(hander) 绑定滚动事件scroll() 触发滚动事件 $(selector).scroll(function(){ //当选择的元素发生滚动的时候触发 });.hover(mousein, mouseleave) //鼠标移入,移出
mouseout: 当鼠标离开元素及它的子元素的时都会触发。
mouseleave: 当鼠标离开自己时才会触发,子元素不触发。
.dbclick() 双击
change 改变,比如:文本框发送改变,下来列表发生改变等...focus 获得焦点keyup, keydown, keypress : 键盘 键被按下。mousedown, mouseover
其他参考:http://www.w3school.com.cn/jquery/jquery_ref_events.asp
优势:效率较高
unbind解绑 bind方式绑定的事件( 在jQuery1.7以上被 on和off代替)
$(selector).unbind(); //解绑所有的事件$(selector).unbind("click"); //解绑指定的事件undelegate解绑delegate事件
$( "p" ).undelegate(); //解绑所有的delegate事件$( "p" ).undelegate( "click" ); //解绑所有的click事件 例如: var foo = function () { // Code to handle some kind of event }; // ... Now foo will be called when paragraphs are clicked ... $( "body" ).delegate( "p", "click", foo ); // ... foo will no longer be called. $( "body" ).undelegate( "p", "click", foo ); off解绑on方式绑定的事件 $( "p" ).off();$( "p" ).off( "click", "**" ); // 解绑所有的click事件,两个*表示所有$( "body" ).off( "click", "p", foo ); 案例1: var foo = function() { // Code to handle some kind of event }; // ... Now foo will be called when paragraphs are clicked ... $( "body" ).on( "click", "p", foo ); // ... Foo will no longer be called. $( "body" ).off( "click", "p", foo ); 案例2:(了解)解绑命名空间的方式: var validate = function() { // Code to validate form entries }; // Delegate events under the ".validator" namespace $( "form" ).on( "click.validator", "button", validate ); $( "form" ).on( "keypress.validator", "input[type='text']", validate ); // Remove event handlers in the ".validator" namespace $( "form" ).off( ".validator" );event.data //传递的额外事件响应方法的额外参数
event.currentTarget //在事件响应方法中等同于this,当前Dom对象
event.target //事件触发源,不一定===this
event.pageX //The mouse position relative to the left edge of the document
event.pageY
event.stopPropagation()//阻止事件冒泡
e.preventDefault(); //阻止默认行为
event.type //事件类型:click,dbclick...
event.which //鼠标的按键类型:左1 中2 右3链式编程: end()补充
补充五角星 评论案例第一步:鼠标移入,当前五角星和前面的五角星变实体。后面的变空心五角星第二步:鼠标点击的时候,为当前元素添加clicked类,其他的移除clicked类第三步:当鼠标移开整个评分控件的时候,把clicked的之前的五角星显示实心隐式迭代
map函数
$.map(arry,function(object,index){}) 返回一个新的数组$("li").map(function(index, element){}) 注意参数的顺序是反的 var newArr = $.map($("li"), function(i, e) { return $(e).text() + i;//每一项返回的结果组成新数组 }); var newArr = $("li").map(function(elem, index){ console.log("elem:" + elem); console.log("index:" + index); retrun index; }); each函数 $.each(array, function(index, object){})$("li").each(index, element )参数的顺序是一致的。 例如: $( "li" ).each(function() { $( this ).addClass( "foo" ); }); $( "li" ).each(function( index ) { console.log( index + ": " + $( this ).text() ); }); $( "div" ).each(function( index, element ) {});+noConflict 全局对象污染冲突
转载于:https://www.cnblogs.com/yiwangdeyidianyuan/p/5850806.html