美文网首页
jQuery 回调函数

jQuery 回调函数

作者: McDu | 来源:发表于2019-07-30 11:21 被阅读0次
  1. cal.add(callbacks)
// a sample logging function to be added to a callbacks list
var foo = function( value ){
    console.log( 'foo:' + value );
}

// another function to also be added to the list
var bar = function( value ){
    console.log( 'bar:' + value );
}
// 创建一个回调函数的列表集合
var callbacks = $.Callbacks();  

// add the function 'foo' to the list
callbacks.add( foo );

//把回调函数集合中的方法执行,并把参数传入对应的方法
callbacks.fire( 'hello' );  
// outputs: 'foo: hello'

// add the function 'bar' to the list
callbacks.add( bar );

// fire the items on the list again
callbacks.fire( 'world' );  

// outputs:
// 'foo: world'
// 'bar: world'

callbacks.remove(foo);
callbacks.fire('word');

// outputs:
// 'bar:world'
  1. attr 一般用来设置和操作元素的自定义属性,prop 一般用来操作元素的内置属性,尤其是对应表单元素(有大量的内置属性,多使用 prop);
    3.选择器第一个参数定义规则,第二个参数(context,不传的话是 ducument)
var $box = $("#box"),
$boxChildren = $("#box > div");

// equal
$boxChildren = $("div", $box);

// equal 
$boxChildren = $box.children("div")

$boxChildren.addClass("clss"); // 给集合里的元素都加了样式,jQuery 会先判断如果是集合调用了 addClass,会用内置循环的方法给每个元素调用 addClass。
  1. jQuery 中通过 for 循环索引获取的元素都是原生的
  2. each() 循环
$list.each(function(index,item){
  $(item).addClass('cc');   // item 是原生的
})

$list.each(function(index,item){
  $(this).addClass('cc');   // item = this
})

[1,2,3].forEach(function(item,index){})
  1. html() 传参设置 html 内容,不传参获取
  2. text() 只得到文字
  3. val() 获取和设置表单元素
  4. offset : 不管父级参照物是谁,获取距 body 的偏移
  5. position: 获取当前元素距父级参照物的偏移
innerWidth(): width + padding
outerWidth(): width + padding + borderWidth
outerWidth(true):width + padding + borderWidth + margin
  1. outerWidth(true): 有 true 表示加外边距
  2. scrollTop/scrollLeft : 元素卷去的高度、宽度

文档处理

  1. append: 向指定元素的末尾追加一个新的元素, append(原生的或jQuery对象)
  2. appendTo
  3. prepend / prependTo: 向指定元素的开头
  4. after / before:指定元素之后/前
  5. (A).insertBefore((B)): A 插入到 B 的前面
  6. 筛选
filter: 同级
children: 子级 children() children(".cll") 
find: 后代
$("*", $box) // jquery 重构出 JQuery 对象
$("*", box) // 第二个参数传入元素,重构出元生的
is:至少有一个符合,返回 true 或 false
  1. parent 、parents
  2. $.each()

相关文章

  • javascript回调函数

    javascript回调函数很玄幻。 jquery 中大量使用了回调函数。直到现在才看懂 普通回调函数 匿名回调函...

  • jQuery-核心函数与工具方法

    jQuery核心函数 jQuery(callback)当DOM加载完成后执行传入的回调函数 jQuery([sel...

  • jQuery 回调函数

    cal.add(callbacks) attr 一般用来设置和操作元素的自定义属性,prop 一般用来操作元素的内...

  • jQuery回调函数

    1.引言 利用回调函数来当参数,会极大的提高程序的灵活性。对回调函数很陌生,研究了一下给的示例程序,感觉对回调函数...

  • JQ第五部分源码学习

    JQ的回调对象处理,通过回调对象管理函数 对函数的统一管理 jQuery.Callbacks = function...

  • jQuery|Callback

    Callback 顾名思义,就是回调的意思,但是在jQuery中这个回调时有个先后顺序的。 Callback 函数...

  • jquery事件绑定

    事件绑定 1. jquery标准的绑定方式 jq对象.事件方法(回调函数); 注:如果调用事件方法,不传递回调函数...

  • jQuery中的deferred对象

    deferred对象简单来说就是jQuery的回调函数解决方案。 一、ajax中的链式写法 jQuery中ajax...

  • 记录14 用键盘控制动画

    使用jQuery $函数来选择HTML中的body元素, 然后,调用keydown 这个回调方法。keydown ...

  • 常用知识点

    属性选择: jQueryUI: 功能 鼠标关标点位到input deferred对象就是jQuery的回调函数解决...

网友评论

      本文标题:jQuery 回调函数

      本文链接:https://www.haomeiwen.com/subject/dbavlxtx.html