JQuery入门到实践(二)
2020-08-19 22:33
706 查看
JQuery HTML操作
-
JQuery常用选择器
$(#id) //id选择器 $(tagname) //标签选择器 $(.classname) //class选择器
-
JQuery常用事件方法
$("button").click(function(){效果代码片}) //单击 $("button").dbclick(function(){效果代码片}) //双击 $("button").mouseenter(function(){效果代码片}) //鼠标移至 $("button").mouseleave(function(){效果代码片}) //鼠标离开 $("button").on(“click”,效果函数名) //绑定事件 $("button").off(“click”) //解除所有绑定事件 $("button").off(“click”,效果函数名) //解除某个绑定事件 event.stopPropagation(); //阻止事件父级冒泡 event.stopImmediatePropagation(); //阻止事件所有冒泡
-
JQuery对HTML DOM元素操作
$(document).ready(function(){ $("button").click(function(){ //捕获DOM内容 console.log($("#text").text()); //获取文本内容 console.log($("#text").html());//获取html内容 console.log($("#ipt").val());//获取输入框中value console.log($("a").attr("href"));//获取a标签的href属性值 //设置DOM内容 $("p").text("设置的新内容"); //设置p标签中文本内容 $("div").html("<a href='www.baidu.com'></a>"); //div中添加a子标签 $("input").val("输入框新内容"); //设置输入框中内容 $("a").attr({ "href":"wwww.google.com", "id":"new_a" ); // 设置a标签的属性值 }); //添加元素及内容(append,prepend添加不换行,before,after添加会自动换行) $("p").append("new content") //元素后面添加内容 var text1 = "<a href=‘baidu.com’>链接</a>" $("p").append(text1); $("p").prepend("new content") //元素前面添加内容 var text2 = $("<a href=‘baidu.com’></a>").text("链接") $("p").prepend(text2); $("p").before("new content") //元素后面添加内容 var text3 = document.createElement("a"); text3.innerHtml = "链接"; $("p").before(text3); $("p").after("new content") //元素后面添加内容 //删除元素(remove是全部删除,empty是删除里面的子元素) $("p").empty(); $("p").remove(); });
相关文章推荐
- JQuery入门到实践(五)
- JQuery入门到实践(六)
- JQuery入门到实践(三)
- jQuery插件开发入门与最佳实践
- JQuery入门到实践(四)
- jQuery入门之一:校验文本,页面提示
- python从入门到实践第18章习题Pizzeria完整版
- Python学习之路——《python编程,从入门到实践》第五章习题
- Linux入门实践笔记(六)——压力测试工具Apache Bench的安装、使用和结果解读
- jQuery入门[3]-事件
- jquery 入门的两篇不错的文章
- jQuery最佳实践
- jQuery插件实践之轮播练习(二)
- jQuery入门学习贴
- 中小研发团队架构实践之RabbitMQ快速入门及应用
- 《Python编程:从入门到实践》学习打卡6-字典
- 《python编程从入门到实践》读书笔记与代码实现(一)
- Storm入门与实践(1)入门介绍
- 第五天任务 (【基于Python编程从入门到实践】第五章 if语句 书本及动手试一试)
- CoffeeScript入门实践