一 jQuery的简单介绍
jQuery是一个快速、简洁的JavaScript框架。jQuery设计的宗旨是“write Less,Do More”,即倡导写更少的代码,做更多的事情。它封装JavaScript常用的功能代码,提供一种简便的JavaScript设计模式,优化HTML文档操作、事件处理、动画设计和Ajax交互。
jQuery的核心特性可以总结为:具有独特的链式语法和短小清晰的多功能接口;具有高效灵活的css选择器,并且可对CSS选择器进行扩展;拥有便捷的插件扩展机制和丰富的插件。
二 jQuery对象与DOM对象关系
jQuery封装了DOM的一些复杂方法,两者可以互相转化,但是两者的方法不能互相混用。
$ele jQuery对象 ele DOM对象 $(ele)-->jQuery对象 $ele[0]--->DOM对象
三 jQuery的操作
http://www.w3school.com.cn/jquery/jquery_ref_selectors.asp 基本选择器 层级选择器 属性选择器 表单选择器 表单属性
http://www.w3school.com.cn/jquery/jquery_selectors.asp
http://www.w3school.com.cn/jquery/jquery_ref_css.asp CSS操作,设置或返回元素的CSS属性
http://www.w3school.com.cn/jquery/jquery_dimensions.asp 尺寸操作
http://www.w3school.com.cn/jquery/jquery_ref_manipulation.asp 文档操作
http://www.w3school.com.cn/jquery/jquery_ref_events.asp 事件参考手册
http://www.w3school.com.cn/jquery/jquery_dom_get.asp 获得内容和属性
http://www.w3school.com.cn/jquery/jquery_dom_set.asp 设置内容和属性
http://www.w3school.com.cn/jquery/jquery_ref_attributes.asp 属性操作
https://www.w3cschool.cn/jquery/html-prop.html prop()方法
http://www.w3school.com.cn/jquery/jquery_ref_effects.asp 效果函数
http://www.w3school.com.cn/jquery/jquery_ref_events.asp 事件
https://www.w3cschool.cn/jquery/event-on.html 事件绑定 on()方法
http://www.w3school.com.cn/jquery/jquery_ref_traversing.asp 遍历函数
http://www.w3school.com.cn/jquery/jquery_ref_data.asp 数据操作——指定的对象与任意数据相关联
http://www.w3school.com.cn/jquery/jquery_ref_ajax.asp jQuery参考手册——Ajax
四 实现快速返回顶部并且实现离顶部一定距离不显示返回按钮,超出一定距离显示返回按钮。
PS:
Window 对象表示浏览器中打开的窗口。如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为每个框架创建一个额外的 window 对象。
Title 112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112112返回
五 利用jQuery实现左侧菜单
Title 菜单一111
111
111
菜单二菜单三
PS
拿到对象后,javascript的方法是.classList.add('')和.classList.remove('')
jQuery方法是$(self),在这里self是形参,代指对象。$(self).next().addClass('') $(self).next().removeClass()。next(),addClass(),removeClass()都是jQuery方法。
升级版
两行代码搞定,一行代码也行。
Title 菜单一111
111
111
菜单二菜单三
八 方法
1 toggle()
示例
Title
- 11
- 22
- 33
六 简单模拟注册页面
Title
七 表格的增删改
周末作业大礼包
# | 姓名 | 爱好 | 操作 |
1 | Egon | 杠娘 | |
2 | Alex | 吹牛逼 | |
3 | 小轩轩 | 抽烟喝酒烫头 |
24 使用 Python 的 Web 框架,做一个 Web 版本 TodoList 应用。
简单实现了下,发现都忘的差不多了。
todo.html
"zh-CN"> "UTF-8"> "X-UA-Compatible" content="IE=edge"> "viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">Title "stylesheet" href="/static/bootstrap-3.3.7-dist/css/bootstrap.min.css">class="container">class="row">class="pull-right">class="row">class="table-bordered table-hover ">
{% for info in infos %} class="col-md-8">任务 class="col-md-4">管理 {% endfor %} {{ info.name }} "">删除 class="row">class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">class="modal-dialog" role="document">class="modal-content">class="modal-header">class="modal-title" id="myModalLabel">任务名称
class="modal-body">class="modal-footer">
views.py
def todo(request): if request.method == 'POST': mission = request.POST.get('mission') if mission: Mission.objects.create(name=mission) return HttpResponse('1') else: return HttpResponse('数据不能为空!') infos = Mission.objects.all() return render(request,'todo.html',{'infos':infos})
总结:
1 模态框与jquery是基友。使用ajax 实现页面局部刷新的功能。
2 使用模态框,提交的button 并不在 form 标签内,所以用,jquery 操作。
3 jquery的基本操作
$('#id') $('.class')
$.ajax({
url:'xx',
type:'post',
data:{'':"},
success:fuction(data){
if () {
location.href='/xx/' #根据后端返回的数据,由前面来实现页面跳转的功能。
}
else{}
}
})