jQuery2

作者: 追逐_e6cf | 来源:发表于2018-10-02 14:55 被阅读0次

一、offsetParent() 定位父节点

$("button").click(function(){
  console.log($("#p").offsetParent());
})

二、parents、closest

//parents  找到元素嵌套的直接父级
//closest  找到元素本身以及嵌套的直接父级
console.log( $('p').parents('.box1') );
console.log( $('p').closest('p') );

三、before、after、append、prepend、replaceWith
before 在元素之前添加
after 在元素之后添加
append 在元素子节点后添加
prepend 在元素子节点前添加
replaceWith 把元素替换

var $boxSec =$(".box").eq(1);
var $newBox = $("<div />", {
  css:{
    width:"100px",
    height:"100px",
    backgroundColor:"pink"
  }
});

$boxSec.before($newBox);
$boxSec.after($newBox);
$boxSec.append($newBox);
$boxSec.prepend($newBox);
$boxSec.replaceWith($newBox);

四、html:添加内容

<p></p>
$("p").html(123);

五、remove、empty、removeClass、addClass
remove:消除本节点以及所有的子节点
empty:消除本节点的内容
removeClass/addClass:移除/添加类名

$(".wrap").remove()
$(".wrap").empty()
$("wrap").removeClass().addClass("newClass");

last().after() 最后的元素的后面
clone() 克隆
当clone的值为true则克隆事件
当clone的值为false则不克隆事件

console.log($(".wrap").clone());
$(".wrap2").last().after($(".wrap1").clone(true));

六、hover

$(".box").hover(function(){
  //移入事件
  $(this).css("background", "black");
}, function(){
  //移出事件
  $(this).css("background", "");
});

七、事件监听

//onclick
//onmouseenter/onmouseleave
//onload
$(".box").on("click", function(){
  console.log(123);
});
$(".box").click(function(){
  console.log(456);
})
//off解绑事件
$(".box").on("click", function(){
  console.log(123);
  $(this).off();
})

相关文章

  • jQuery2

    一、offsetParent() 定位父节点 二、parents、closest 三、before、after、...

  • jQuery2

    jQuery 中, $(document).ready()是什么意思? 当DOM加载完毕以后,执行指定的代码 wi...

  • jQuery2

    第三章******************************************************...

  • jquery2

    1 jquery中如何来获取或和设置属性? attr()方法用来获取和设置属性,removeAttr() 方法用来...

  • jQuery

    基础语法:$(selector).action()1)美元符号定义jQuery2)选择符(selector)“查询...

  • vue与bootstrap学习笔记(1)|实现表格分页功能

    1、首先需要在vue-cli项目中配置bootstrap,jquery2、 然后新建vue文件,如index.vu...

  • 5.JSON和XML的转换

    5.JSON和XML的转换 14:21 1. 下载相关文件 1)jquery官网下载:JQuery2)https:...

  • Vue脚手架匹配jq bootstrap

    想要在vue中引入bootstrap,引入的时候需要按照如下的步骤进行。 1、引入jquery2、引入bootst...

  • Days17 jQuery2

    1.val方法 2.html方法与text方法 html方法相当于innerHTML text方法相当于inne...

  • 制作demo

    开发一个demo一般有三种方式1、通过$.extend()来扩展jQuery2、通过$.fn 向jQuery添加新...

网友评论

      本文标题:jQuery2

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