查找:
选择器
筛选器

操作:
CSS
属性
文本

事件:
优化

扩展:
Form表单验证

Ajax:
偷偷发请求

www.php100.com/manual/jquery

http://blog.jquery.com/category/jquery/

利用JQuery实现左侧菜单的隐藏与显示

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.hide{
display: none;
}
.menu{
height: 600px;
width: 200px;
line-height: normal;
border: 1px solid darkgray;
overflow: auto;
}
.menu .item .title{
height: 40px;
line-height: 40px;
background-color: #2459a2;
}
</style>
</head>
<body>
<div class="menu">
<div class="item">
<div class="title" onclick="ShowMenu(this);">标题一</div>
<div class="body">
<p>内容一</p>
<p>内容一</p>
<p>内容一</p>
<p>内容一</p>
<p>内容一</p>
<p>内容一</p>
</div>
</div>
<div class="item">
<div class="title" onclick="ShowMenu(this);">标题二</div>
<div class="body hide">
<p>内容二</p>
<p>内容二</p>
<p>内容二</p>
<p>内容二</p>
<p>内容二</p>
</div>
</div>
<div class="item">
<div class="title" onclick="ShowMenu(this);">标题三</div>
<div class="body hide">
<p>内容三</p>
<p>内容三</p>
<p>内容三</p>
<p>内容三</p>
<p>内容三</p>
<p>内容三</p>
</div>
</div>
</div>
<script src="jquery-1.12.4.js"></script>
<script>
//$(ths) DOM转化为JQuery
//$(ths)[0] JQuery转化为DOM
function ShowMenu(ths){
$(ths).next().removeClass("hide");
$(ths).parent().siblings().find('.body').addClass("hide");
}
</script>
</body>
</html>

JQuery实现多选框的多选和反选

    <script src="jquery-1.12.4.js"></script>
<script>
function CheckALL(){
$('#tb input[type="checkbox"]').prop('checked',true); } function CancelALL(){
$('#tb input[type="checkbox"]').prop('checked',false); } function ReverseALL(){
$('#tb input[type="checkbox"]').each(function(i){
if($(this).prop("checked")){
$(this).prop("checked",false);
}else{
$(this).prop("checked",true);
}
})
</script>

JQuery实现复制删除标签

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div>
<p>
<a onclick="Add(this)"> + </a>
<input type="text" />
</p>
</div>
<script src="jquery-1.12.4.js"></script>
<script>
function Add(ths){
var p = $(ths).parent().clone();
p.find('a').text('-')
p.find('a').attr('onclick','Remove(this)');
$(ths).parent().parent().append(p);
} function Remove(ths){
$(ths).parent().remove();
}
</script>
</body>
</html>

JQuery实现的菜单展开与收起

        $('.item .title').bind('click',function(){
$(this).next().removeClass("hide");
$(this).parent().siblings().find('.body').addClass("hide");
}) $('.item .title').click(function(){
$(this).next().removeClass("hide");
$(this).parent().siblings().find('.body').addClass("hide");
})

当文档树已经加载完毕了,但是加载的图片还没有出现的时候,后面的代码可以执行,写法如下:

$(function(){
.......
});

JQuery延迟绑定,delegate,什么时候用的时候绑定。

<body>
<input type="button" onclick="Add()"/>
<ul>
<li>第一课</li>
<li>第二课</li>
<li>第三课</li>
</ul>
<script src="jquery-1.12.4.js"></script>
<script>
$(function(){
$("ul").delegate("li","click", function (){
alert($(this).text());
})
}) function Add(){
var tag = document.createElement('li');
tag.innerText = '666';
$('ul').append(tag);
}
</script>
</body>

JQuery之表单验证:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.item{
width: 200px;
/*background-color: #2459a2;*/
height: 60px;
/*color: white;*/
position: relative;
}
.item input{
width: 196px;
}
.item span{
/*width: 202px;*/
/*color: red;*/
position: absolute;
background-color: red;
color: white;
/*display: inline-block;*/
top: 20px;
left: 0;
width: 200px;
height: 22px;
}
</style>
</head>
<body>
<div>
<form>
<div class="item">
<input class="c1" type="text" name="username" label="用户名"/>
<!--<span>不能为空</span>-->
</div>
<div class="item">
<input class="c1" type="password" name="pwd" label="密码"/>
<!--<span>不能为空</span>-->
</div>
<input type="submit" value="提交" onclick="return CheckValid()"/>
</form>
</div>
<script src="jquery-1.12.4.js"></script>
<script>
function CheckValid(){
// $('form .c1')
// $('form input[type="text"],form input[type="password"]')        $('form .item span').remove(); //如果第一次没有输入,那么下面会显示错误信息,第二次输入后,错误信息应该被清除,所以在添加span之前,首先把所有的span标签清除
var flag = true;
$('form .c1').each(function(){
var val = $(this).val();
if (val.length <=0){
var label = $(this).attr('label');
var tag = document.createElement('span');
tag.innerText = label + '不能为空';
$(this).after(tag);
flag = false;
            return false;
}
})
return flag;
}
</script>
</body>
</html>

利用JQuery来实现绑定:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.item{
width: 200px;
/*background-color: #2459a2;*/
height: 60px;
/*color: white;*/
position: relative;
}
.item input{
width: 196px;
}
.item span{
/*width: 202px;*/
/*color: red;*/
position: absolute;
background-color: red;
color: white;
/*display: inline-block;*/
top: 20px;
left: 0;
width: 200px;
height: 22px;
}
</style>
</head>
<body>
<div>
<form>
<div class="item">
<input class="c1" type="text" name="username" label="用户名"/>
<!--<span>不能为空</span>-->
</div>
<div class="item">
<input class="c1" type="password" name="pwd" label="密码"/>
<!--<span>不能为空</span>-->
</div>
<input type="submit" value="提交" />
</form>
</div>
<script src="jquery-1.12.4.js"></script>
<script>
$(function(){
BindCheckValue();
}) function BindCheckValue(){
$('form input[type="submit"]').click(function() { var flag = true;
$('form .item span').remove();
$('form .c1').each(function () {
var val = $(this).val();
if (val.length <= 0) {
var label = $(this).attr('label');
var tag = document.createElement('span');
tag.innerText = label + '不能为空';
$(this).after(tag);
flag = false;
}
})
return flag;
})
}
// function CheckValid(){
//// $('form .c1')
//// $('form input[type="text"],form input[type="password"]')
// $('form .item span').remove();
// var flag = true;
// $('form .c1').each(function(){
// var val = $(this).val();
// if (val.length <=0){
// var label = $(this).attr('label');
// var tag = document.createElement('span');
// tag.innerText = label + '不能为空';
// $(this).after(tag);
// flag = false;
// }
// })
// return flag;
// }
</script>
</body>
</html>

JQuery之each

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="jquery-1.12.4.js"></script>
<script>
function Test(){
$.each([11,22,33,44],function(k,v){
console.log(k,v)
if (v == 22){
return; //continue
}
if (v == 33){
return false; //break
}
});
}
Test()
</script>
</body>
</html>
执行结果:
0 11
1 22
2 33

JQuery之扩展方法:

假设需要导入extend1.js和extend2.js,由于同时具有两个f1()函数,因此需要使用函数的闭包来处理。

//extend1.js
$.extend({
'dalong1':function(arg){
console.log(arg);
}
}); function f1(){ }
===========================================
//extend2.js
$.extend({
'dalong2':function(arg){
console.log(arg);
}
}); function f1(){ }

那么经过修改之后的函数为:

//extend1.js
a = function(){
$.extend({
'dalong1':function(arg){
console.log(arg);
}
}); function f1(){ }
}; ==================================
//extend2.js
b = function(){
$.extend({
'dalong2':function(arg){
console.log(arg);
}
}); function f1(){ }
};

像上面那么书写了以后,函数只是被定义了但是不会执行,执行的时候报错:

Uncaught TypeError: $.dalong1 is not a function

因为函数默认不会执行,只能在后面添加a();和b(); ,既然如此,就可以写成自执行函数的方式:

extend1.js

(function(){
$.extend({
'dalong1':function(arg){
console.log(arg);
}
}); function f1(){ }
})();
===============================
extend2.js
(function(){
$.extend({
'dalong2':function(arg){
console.log(arg);
}
}); function f1(){ }
})();

在导入的JS里面,使用到了$,那么如果我们需要将JQuery以参数的形式传递到JS里面,代码可以做如下的修改:

//extend1.js

(function(jq){
jq.extend({
'dalong1':function(arg){
console.log(arg);
}
}); function f1(){ }
})($); ================================ //extend2.js (function(jq){
jq.extend({
'dalong2':function(arg){
console.log(arg);
}
}); function f1(){ }
})(jQuery);

Python 前端之JQuery的更多相关文章

  1. Python web前端 09 jQuery

    Python web前端 09 jQuery 一.三个重要网址 http://jquery.cuishifeng.cn/ #中文查询网站 http://www.bootcdn.cn/ #引入jq ht ...

  2. 前端之jquery

    前端之jquery 本节内容 jquery简介 选择器和筛选器 操作元素 示例 1. jquery简介 1 jquery是什么 jQuery由美国人John Resig创建,至今已吸引了来自世界各地的 ...

  3. 第四篇:web之前端之jquery

    前端之jquery   前端之jquery 本节内容 jquery简介 选择器和筛选器 操作元素 示例 1. jquery简介 1 jquery是什么 jQuery由美国人John Resig创建,至 ...

  4. 【前端】:jQuery下

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

  5. 【转】jQuery之前端国际化jQuery.i18n.properties

    jQuery之前端国际化jQuery.i18n.properties 基于jQuery.i18n.properties 实现前端页面的资源国际化 jquery-i18n-properties

  6. 前端:jQuery笔记

    前端:jQuery笔记 此系列文章乃是学习jQuery的学习笔记. Asp.net MVC Comet推送 摘要: 一.简介 在Asp.net MVC实现的Comet推送的原理很简单. 服务器端:接收 ...

  7. 前端技术Jquery与Ajax使用总结

    前端技术Jquery与Ajax使用总结 虽然主要是做的后端,但是由于有些时候也要写写前台的界面,因此也就学习了下Jquery和Ajax的一些知识,虽说此次写的这些对于前端大神来说有些班门弄斧的感觉,但 ...

  8. Golang 谷歌搜索api 实现搜索引擎(前端 bootstrap + jquery)

    Golang 谷歌搜索api 实现搜索引擎(前端 bootstrap + jquery) 体验 冒号搜索 1. 获取谷歌搜索api 谷歌搜索api教程 2. 后台调用 程序入口 main.go // ...

  9. 第五章、前端之JQuery

    目录 第五章.前端之JQuery 一.选择器 二.基本筛选器 三.样式操作 四.位置操作 五.文本操作 六.属性操作 七.文档处理 八.事件 九.动画效果 十.补充 第五章.前端之JQuery 一.选 ...

随机推荐

  1. 使用notepad++进行格式转换

    由于历史原因,导致Windows.Unix/Linux.Mac三者之间,对于文本中所用回车换行符,表示的方法,都不一样.这就导致了很多人都会遇到回车换行符的困惑,同时需要在不同格式间进行转换. 1)查 ...

  2. maven 基本常识以及命令

    Maven库: http://repo2.maven.org/maven2/ Maven依赖查询: http://mvnrepository.com/ Maven常用命令: 1. 创建Maven的普通 ...

  3. HDU 2717 Catch That Cow (bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2717 Catch That Cow Time Limit: 5000/2000 MS (Java/Ot ...

  4. mactype支持qq浏览器

    win7上使用mactype之后qq浏览器网页显示的字体不清晰,颜色也比较浅.解决方法: 1. 再qq浏览器地址栏中输入:qqbrowser://flags 2.在设置中启用DirectWrite高清 ...

  5. 10-Java 网络通信

    (一) Java中的XML操作 1.XML数据格式简介: (1)XML,即可扩展标记语言(Extensible Markup Language),标准通用标记语言的子集,一种用于标记电子文件使其具有结 ...

  6. Docker SSH

    1. Dockerfile   -->docker build -t centos6-ssh https://git.oschina.net/feedao/Docker_shell/raw/st ...

  7. 第三节:视图(Views)和模板(Templates)

    目录 概览 编写视图 编辑视图实际做一些事情 抛出404异常 使用模板系统 移除在代码中的硬编码网址 Url名称的命名空间 概览 视图是Django应用的网页的“类型”,一般服务于特定的功能并且有特定 ...

  8. Activity和Service是否是在同一个进程中运行。

    一般情况下,Activity和Service在同一个包名内,并且没有设定属性android:process=":remote",两者在同一个进程中. 因为一个进程只有一个UI线程, ...

  9. JavaScript中的继承(原型链)

    一.原型链 ECMAScript中将原型链作为实现继承的主要方法,基本思想是利用原型让一个引用类型继承另一个引用类型的属性和方法. 实例1: function SupType() { this.pro ...

  10. yii2安装

    https://github.com/settings/tokens  设置token 在安装的时候 要复制进去 复制到安装命令中去