查找:
选择器
筛选器

操作:
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. Windows 2012 装 Remote Desktop Organizer 无法连接到其他远程服务器

    一句话,版本太低 换Remote Desktop Organizer 1.4.5版本就ok 了

  2. RocketMQ生产者示例程序

    转载请注明出处:http://www.cnblogs.com/xiaodf/ 本示例展示了一个RocketMQ producer的简单实现,通过解析文本文件获取输入数据,将数据经过Avro序列化后发送 ...

  3. java 读写JSON(一)

    算是第一次正式接触Json,没有深入研究,先贴上java的代码,日后才说! package priv.chenhy.datehandle; import java.io.BufferedReader; ...

  4. Android:给ViewPager添加切换效果

    原文参照开发者官网:http://developer.android.com/training/animation/screen-slide.html#viewpager 以App的引导页为例: 首先 ...

  5. ;function($,undefined) 前面的分号是什么用处

    ;function($,undefined) 前面的分号是什么用处 ;(function($){$.extend($.fn...现般在一些 JQuery 函数前面有分号,在前面加分号可以有多种用途:1 ...

  6. 给JavaScript初学者的24条最佳实践(share)

    不错的文章,留个备份 原文链接: net.tutsplus   翻译: 伯乐在线- yanhaijing译文链接: http://blog.jobbole.com/53199/ 作为“30 HTML和 ...

  7. jQuery plugin: Autocomplete 参数及实例

    官网:jQuery plugin: Autocomplete          (注:此插件已经不再更新.它的继任者是jQuery UI的一部分,) 此插件依赖于 jquery 1.2.6 --- j ...

  8. s查找父节点

    查找所有的父节点,包括本身,不包括就<>id with tbs as(select * from TB_HomeBase where ID=223 union all select a.* ...

  9. hdu 1016

    这是一道考搜索的题目.这道题我用深搜解决了,不过说实话自己对于深搜理解得并不深刻,在这里对于这一题总结一下. 这道题输入为一个实数n,要求输出有1~n这n个数所组成的所有素数环(这是素数环),素数环的 ...

  10. tomcat 清理日志

    clear_log.sh #!/bin/bash #clear tomcat logs #log size (1M bytes),if lt, clear LOG_FILE_SIZE=1024000 ...