[关闭]
@File 2019-10-08T11:17:01.000000Z 字数 2734 阅读 140

jquery

web


jQuery对象

$("") # . div *
获取元素 选择某个id 选择某个class 选择div标签 选择整体
ul,li body div body > div #x + div #x ~ div
ul和li body里所有div body理的子div x的下一个div x后面所有的
:odd :even :not() :last :first
基数 偶数 不是 最后一个 第一个
:eq(3) :gt(3) :lt() :header :animated
等于3 大于3 小于3 标题 动画的
:contains() :empty :has() :parent :not(:empty)
文本中含有() 空的 含有()元素的元素 不是空的 不是空的
:visible :hidden :not() :last :firsh
可见的 不可见的 不是 最后一个 第一个

jQuery方法

.click() .css() .siblings() .nextAll() prevAll()
点击时 的属性 兄弟级的 后面所有的 后面所有的
.ready .show .val() [] :firsh
准备好时 显示出来 value属性值 含有 第一个
.removeClass() .addClass() .toggleClass() .toggle() :hide()
删除属性 添加属性 切换属性 切换(默认点击) 隐藏元素
.appendTO() .addpend() .remove() .toggle() :contains()
添加到 里添加 清楚元素内容 删除元素 内容含有
.clone() .clone(true) .replaceAll() .replaceWith() .find()
复制 全复制 替换 替换为 的后代元素
.children() .dbclick() .hover() .on() .focus()
的子元素 鼠标双击时 鼠标覆盖时 添加事件 光标焦点时
.blur() .change() .submit() .keydown() .keypress()
撤销焦点时 内容改变时 提交的时候 键按下过程时 键被按下时
.keyup() .off() .slideDown() .slideUp() .slideToggle()
键松开时 取消事件 滑动显示 滑动隐藏 滑动效果切换
.fadeOut() .fadeIn() .fadeToggle() .attr() .html()
淡出 淡入 淡出淡入切换 的属性 的内容
.scrollable() .autoscroll() .each() $.trim() .clone()
滚动 自动翻滚 循环每个 去除两端的空格 克隆
.clone(true) .insertAfter() .wrap() .wrapAll() .wrapInner()
全克隆 元素插入元素后 被元素单独包裹 被元素全包裹 里的内容被包裹
.prepend() .prependTo() .insertBefore() .empty() .hasClass()
里添加 添加到 元素插入元素前 清空 查找class
.width(100) .height(100) .hide() .is() .bind()
宽度100 高度100 隐藏 判断是否 绑定事件
.pageX() .pageY() .unbind() .one() .fadeTo(t,1)
光标X轴参数 光标y轴参数 取消事件 只触发一次 透明度变成
JSON.stringify() .change() .select() .animated() .touchstart()
对象转为字符串 改变文本时 扩选文本时 创建动画 触摸屏幕时
.touchmove() .touchend() .touchcancel() .touches() .targetTouches()
触屏滑动时 触屏结束时 系统停止跟踪触屏时 屏幕上的所有触点的数组 对象上的触点的数组
.changedTouches() .() charAt.() .() .()
事件中的触点的数组 获取第某个字符

.css("background" , "#ffbbaa") 样式改变背景颜色;
.hover(覆盖时 , 离开时) 鼠标覆盖事件的使用;
return false 1) 清楚默认行为 2) 阻止事件冒泡;
var a = JSON.stringify(b) 将b转换为字符串形式;


练习案例

1. 表格录入及删除信息
  1. //在body元素中.添加("点击事件",点击"id名为table的元素里的a元素"时,发生匿名事件{反馈值到removeTr(值为"#table a")}
  2. /*以下为错误示范:
  3. $("#table a").click(function(){
  4. return removeTr(this)
  5. })
  6. 错误原因:由于表格的内容即所点击的对象"#table a"是经过#button的点击事件下动态产生出的元素,无法从html文档里直接获取,要使用 .on 委托父元素查找出所需要的元素。
  7. */
  8. $("body").on("click","#table a",function(){
  9. return removeTr(this)
  10. })
  11. $("#button").click(function(){
  12. $("<tr></tr>").append("<td>" + $("#name").val() + "</td>")
  13. .append("<td>" + $("#email").val() + "</td>")
  14. .append("<td>" + $("#salary").val() + "</td>")
  15. .append("<td><a href='#'>Delete</a></td>")
  16. .appendTo("#table tbody")
  17. //点击反馈方法2:
  18. .find("a")
  19. .click(function(){
  20. return removeTr(this)
  21. })
  22. })
源文件地址
2. 元素替换和插入
  1. $(function(){
  2. alert(1);
  3. var $bj2 = $(".bj").clone().attr("class","bj2");
  4. var $gz = $(".gz").replaceWith($bj2);
  5. alert(2);
  6. $(".bj").replaceWith($gz);
  7. })
源文件地址
3. css和js动画
  1. $("#kf").hover(function (){
  2. $(this).animate({right:"0px"});
  3. $('.kf-l').text('客服中心>>');
  4. }, function () {
  5. $(this).animate({right:"-170px"});
  6. $('.kf-l').text('客服中心<<');
  7. });
源文件地址
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注