二十五、jquery的事件

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery的事件</title>
</head>
<body>
<!-- https://www.processon.com/view/link/5ad1c48de4b0b74a6dd65426
js的事件流 的流程图 。。。
事件监听器的方法
事件捕获
处于目标
事件冒泡
jquery的事件 不支持 事件捕获 --> <div id="box">
<button>按钮</button>
</div> </body>
<script src="jquery-3.2.1.js"></script>
<script type="text/javascript"> $('button').click(function () { alert('button事件触发')
}); $('#box').click(function () { //冒泡了 会触发box
alert(222);
}) </script>
</html>

二十六、jquery事件对象和事件冒泡

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery事件对象和事件冒泡</title>
<style type="text/css">
#box{width: 200px;height: 200px;background-color: gray;}
p{width: 100px;height: 100px;background-color: red;} </style> </head>
<body>
<div id="box">
<p class="p1"></p> <a href="https://www.luffycity.com">路飞</a> </div>
</body>
<script src="jquery-3.2.1.js"></script>
<script type="text/javascript"> // 入口函数 事件属性
$(function () { //事件对象
$('.p1').click(function (ev) { console.log(ev.type);
console.log(ev.target);
console.log(ev.pageX);
console.log(ev.pageY); alert('当前按钮触发了');
//常用的事件 方法 1.阻止事件冒泡 2.阻止默认事件
//1,阻止事件冒泡
ev.stopPropagation() //2.组织默认事件 a href = '' form submit }); $('#box').click(function () {
alert('box 事件触发了');
}); $('a').click(function (ev) { //所有额的dom元素都能加 点击事件 //组织a 标签的默认事件
// ev.preventDefault();
// alert('阻止了默认的');
// ev.stopPropagation();
// alert('阻止了冒泡'); return false; // 阻止了冒泡 和 默认 jquery 是没有捕获的 只有冒泡 }) }) // https://www.processon.com/view/link/5ad1c48de4b0b74a6dd65426 </script>
</html>

二十七、jquery事件绑定和移除

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery事件绑定和移除</title>
<style type="text/css">
#box{width: 200px;height: 200px;background-color: red;} </style>
</head>
<body>
<div id="box"> </div> <button>按钮</button> </body>
<script src="jquery-3.2.1.js"></script>
<script type="text/javascript"> $(function () { //事件的绑定 //给当前的dom元素添加绑定事件
$('#box').click(function () { }); //给当前的dom元素绑定事件 语法:jquery对象.bind('事件类型',fn)
$('#box').bind('click mouseenter',function () {
alert('事件被绑定了')
}); $('body').append('<div style="width: 200px;height: 200px;background-color: yellow;">哈哈</div>') function add() {
console.log('click')
}
function add2() {
console.log('mouseover');
}
//给jquery 添加不同的事件 不同的效果
$('div').bind({
'click':add,
'mouseover':add2
}); //事件移除
// 没有参数 表示移除所有事件
setTimeout(function () {
// $('#box').unbind();
// $('#box').unbind('click'); //移除一个事件
},3000); //添加的事件不能发生在未来 --》 动态生成的元素不能直接添加对象 里面的事件也不能发生了-->想让发生,事件代理
// $('body').append('<div style="width: 200px;height: 200px;background-color: yellow;">哈哈</div>') //绑定自定义的事件
$('button').bind('myclick',function (ev,a,b,c) {
alert(11111);
console.log(ev);
alert(a);
alert(b);
alert(c);
});
//触发自定义的事件
// $('button').trigger('myclick')
$('button').trigger('myclick',[1,2,3]) }) </script>
</html>

二十八、事件代理

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>事件代理</title>
</head>
<body>
<ul>
<li class="luffy">路飞</li>
<li>路飞</li>
<li>路飞</li>
</ul>
</body>
<script src="jquery-3.2.1.js"></script>
<script type="text/javascript"> $(document).ready(function () { //先点击
$('ul>li').bind('click',function () {
console.log($(this))
});
$('ul>li').click(function () {
console.log($(this))
}); //事件代理 自己完成不了当前的点击事件,交给父级元素做这件事件
//父级.on('事件名字','点击当前的标签元素选择器',fn) $('ul').on('click','#name,.luffy',function () { // 可绑定多个选择器
console.log(this);
}); $('ul').append('<li id="name">哈哈</li>') // 这时点击 不起作用 需要 代理 }) </script>
</html>

二十九、鼠标事件

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>鼠标事件</title>
<style type="text/css">
*{padding: 0;margin: 0;}
#box{width: 200px; height: 200px;background-color: gray;}
#child{width: 100px; height: 100px;background-color: yellow;}
</style>
</head>
<body>
<div id="box">
<div id="child"></div> <input type="text" value="123">
<br>
<input type="password" >
</div>
</body>
<script src="jquery-3.2.1.js"></script>
<script type="text/javascript"> $(document).ready(function () { //点击事件 //单击
$('#box').click(function () {
console.log('click');
}); //双击
$('#box').dblclick(function () {
console.log('dblclick');
}); //鼠标按下不松开
$('#box').mousedown(function () {
console.log('mousedown');
}); //鼠标松开
$('#box').mouseup(function () {
console.log('mouseup');
}); //被选元素和子元素被选中时会触发 移入移出
$('#box').mouseover(function() {
console.log('mouseover')
}); $('#box').mouseout(function() {
console.log('mouseout')
}); //只有被选中元素移入时 才会触发
$('#box').mouseenter(function() {
console.log('mouseenter')
}); $('#box').mouseleave(function() {
console.log('mouseleave')
}); $('#box').mousemove(function () {
console.log('mousemove')
}); //获取焦点 失去焦点
$('input[type=text]').focus(function () {
console.log($(this).val());
}); $('input[type=text]').blur(function () {
console.log($(this).val());
}); //键盘按下 弹起
$('input[type=password]').keydown(function () {
console.log($(this).val())
});
$('input[type=password]').keyup(function () {
console.log($(this).val())
}); }) </script>
</html>

三十、表单事件

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>表单事件</title>
<style type="text/css">
.show{
color: red;
} </style>
</head>
<body>
<form action="https://www.luffycity.com">
<select name="sweets" id="1" multiple=''>
<option value="">巧克力</option>
<option value="" selected=''>糖果</option>
<option value="">焦糖</option>
<option value="" selected=''>曲奇饼</option>
<option value="">烧饼</option>
<option value="">麦香饼</option>
<option value="">曲奇饼2</option>
</select> <input type="text" value="hello" id='target'>
<input type="submit" value="Luffy"/>
<input type="button" name="" id="2" value="按钮" /> </form> <input id="other" type="text" value="Trigger the handler">
<!--<textarea name="" id="other" cols="30" rows="10">Trigger the handler</textarea>-->
<!--<div id="other">-->
<!--Trigger the handler-->
<!--</div>--> <div class="show"></div>
</body>
<script src="jquery-3.2.1.js"></script>
<script type="text/javascript"> //change() 事件 //此事件仅限于 input元素 textarea select $('select').change(function () {
console.log($('select option:selected').text()); $('.show').text($('select option:selected').text()); }); //select() 事件
//仅限于用在 input type=text textarea
$('#other').select(function () {
// console.log($(this).text())
console.log($(this).val())
}); //form
$('form').submit(function (ev) {
// alert(111);
ev.preventDefault(); // 阻止默认行为 action 就被阻止了 //form 表单和服务端有很大挂钩
alert(11);
}) </script>
</html>

三十一、jquery的ajax

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ajax</title>
</head>
<body>
<button id="btn">演示</button>
<div id="box"> </div>
</body>
<script src="jquery-3.2.1.js"></script>
<script type="text/javascript">
$(document).ready(function () { $('#btn').click(function () {
$('#box').load('./test.html');
}); //get
$.ajax({
// url:'./data.json',
url:'./test.html',
type:'get', // 默认是 get
// dataType:'json', // 如果不指定 默认自动识别文件类型
// dataType:'text',
success:function (data) {
console.log(data);
},
error:function () { }
}); //post 无法演示 学django 会学
$.ajax({
url:"/course",
type:'post',
data:{
username:'zhangsan',
password:'123'
},
sunccess:function (data) {
if(data.state === 'ok' && data.status === '200'){
//登录成功
}
},
error:function () {
console.log(err);
}
}); }) // 插件 == js
// 组件 = js + css
</script>
</html>

前端开发 - JQuery - 下的更多相关文章

  1. 【前端】:jQuery下

    前言: 接上一篇博客: [前端]:jQuery上 一.jQuery属性操作 ① attr(设置或返回自定义属性值) input.select.textarea框中的内容, 可以通过attr来获取,但是 ...

  2. 前端开发 - JQuery&Bootstrap - 总结

    一.JavaScript和Jquery的区别 1.javascript的缺点: 1.书写繁琐,代码量大 2.代码复杂 3.动画效果,很难实现.使用定时器 各种操作和处理 2.定义: 1.Javascr ...

  3. 前端开发 - JQuery - 上

    一.js的缺点 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  4. 前端开发 - jQuery

    本节内容 一.jQuery概述 二.选择器 三.操作DOM 四.修改DOM结构 五.事件 六.动画 七.AJAX(待续) 八.扩展(待续) 一.jQuery概述 jQuery 是一个 JavaScri ...

  5. 前端开发—jQuery

    jquery简介 jQuery是一个轻量级的.兼容多浏览器的JavaScript库. jQuery使用户能够更方便地处理HTML Document.Events.实现动画效果.方便地进行Ajax交互, ...

  6. Web前端开发JQuery框架

    JQuery 是一个兼容多浏览器支持的JavaScript库,其核心理念是write less,do more(写得更少,做得更多),它是轻量级的js库,兼容CSS3还兼容各种浏览器,需要注意的是后续 ...

  7. 第十一章 前端开发-jQuery

    11.4.0 jQuery 11.4.1 基本知识 定义: jQuery是一个快速,小巧,功能丰富的JavaScript库 作用:它通过易于使用的API在大量浏览器中运行,使得HTML文档遍历和操作, ...

  8. 前端开发 - JQuery - 中

    十四.jquery属性操作 attr prop <!DOCTYPE html> <html lang="en"> <head> <meta ...

  9. 前端开发 - JavaScript - 下

    12.数组 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

随机推荐

  1. CentOS6.2下安装配置MySql

    转自:Linux学习之CentOS(十三)--CentOS6.4下Mysql数据库的安装与配置 如果要在Linux上做j2ee开发,首先得搭建好j2ee的开发环境,包括了jdk.tomcat.ecli ...

  2. FreeRTOS 临界段和开关中断

    以下转载自安富莱电子: http://forum.armfly.com/forum.php 临界段代码的临界段也称为临界区,一旦这部分代码开始执行,则不允许任何中断打断.为确保临界段代码的执行不被中断 ...

  3. js代码中定义后台java中的上下文路径

    var href = <c:out value='${sessionScope.contextPath}' />

  4. Bootstrap学习笔记(6)--导航居中

    说明:没找到好办法 <div class="row"> <ul class="nav nav-pills col-md-offset-4"&g ...

  5. 禁止sethc.exe运行 防止3389的sethc后门

    废话:在土司看到的一篇文章,发私信给那个哥们儿说让不让转载,结果还没回复我就在百度看到相同的文章.他自己也是转载的.这哥们儿ID迟早被ban 文章转载自:http://www.jb51.net/hac ...

  6. [shell]C语言调用shell脚本接口

    Use popen if you want to run a shell command and want the parent process to be able to talk to the c ...

  7. 数据库 Oracle数据库对象一

    常见的数据库对象 表:基本的数据存储集合,由行和列组成 视图:从表中抽出的逻辑上相关的数据集合 序列:提供有规律的数值 索引:提高查询的效率 同义词:给对象起别名 create table语句 --c ...

  8. sours insight 使用技巧

    最终在团队的气氛下还是拿回了source insight编译器: Source Insight实质上是一个支持多种开发语言(java,c ,c 等等)的编辑器,只不过由于其查找.定位.彩色显示等功能的 ...

  9. cf490 C. Hacking Cypher(无语)

    http://codeforces.com/contest/490/problem/C 表示我考场上犯逗.. 这个拆成霍纳边乘边mod即可.. 为毛我考场胡思乱想? #include <cstd ...

  10. html的a标签的 href 和 onclick。

    主要用于给超链接添加点击事件. aa.html <html> <body> <span>this si</span> </body> < ...