Python 前端之JQuery
查找:
选择器
筛选器
操作:
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的更多相关文章
- Python web前端 09 jQuery
Python web前端 09 jQuery 一.三个重要网址 http://jquery.cuishifeng.cn/ #中文查询网站 http://www.bootcdn.cn/ #引入jq ht ...
- 前端之jquery
前端之jquery 本节内容 jquery简介 选择器和筛选器 操作元素 示例 1. jquery简介 1 jquery是什么 jQuery由美国人John Resig创建,至今已吸引了来自世界各地的 ...
- 第四篇:web之前端之jquery
前端之jquery 前端之jquery 本节内容 jquery简介 选择器和筛选器 操作元素 示例 1. jquery简介 1 jquery是什么 jQuery由美国人John Resig创建,至 ...
- 【前端】:jQuery下
前言: 接上一篇博客: [前端]:jQuery上 一.jQuery属性操作 ① attr(设置或返回自定义属性值) input.select.textarea框中的内容, 可以通过attr来获取,但是 ...
- 【转】jQuery之前端国际化jQuery.i18n.properties
jQuery之前端国际化jQuery.i18n.properties 基于jQuery.i18n.properties 实现前端页面的资源国际化 jquery-i18n-properties
- 前端:jQuery笔记
前端:jQuery笔记 此系列文章乃是学习jQuery的学习笔记. Asp.net MVC Comet推送 摘要: 一.简介 在Asp.net MVC实现的Comet推送的原理很简单. 服务器端:接收 ...
- 前端技术Jquery与Ajax使用总结
前端技术Jquery与Ajax使用总结 虽然主要是做的后端,但是由于有些时候也要写写前台的界面,因此也就学习了下Jquery和Ajax的一些知识,虽说此次写的这些对于前端大神来说有些班门弄斧的感觉,但 ...
- Golang 谷歌搜索api 实现搜索引擎(前端 bootstrap + jquery)
Golang 谷歌搜索api 实现搜索引擎(前端 bootstrap + jquery) 体验 冒号搜索 1. 获取谷歌搜索api 谷歌搜索api教程 2. 后台调用 程序入口 main.go // ...
- 第五章、前端之JQuery
目录 第五章.前端之JQuery 一.选择器 二.基本筛选器 三.样式操作 四.位置操作 五.文本操作 六.属性操作 七.文档处理 八.事件 九.动画效果 十.补充 第五章.前端之JQuery 一.选 ...
随机推荐
- RSS(Residual Sum of Squares)的自由度为什么是n-1呢
[转载请注明出处]http://www.cnblogs.com/mashiqi 在回归问题中,偶尔我们会遇到求方差的估计的情况.举了例子,我们常常通过Gaussian分布${\cal N}(\mu , ...
- 路由器DHCP 动态主机配置
进入ip设置:ip pool fw 添加网关gateway-list 192.168.1.1 添加网段network 192.168.1.0 mask 255.255.255.0 域名 dns-lis ...
- Angularjs中的promise
promise 是一种用异步方式处理值的方法,promise是对象,代表了一个函数最终可能的返回值或抛出的异常.在与远程对象打交道非常有用,可以把它们看成一个远程对象的代理. 要在Angular中创建 ...
- LintCode Reverse LinkedList (ArrayList 和 LinkedList 的区别)
1. ArrayList 和 LinkedList 的区别 http://pengcqu.iteye.com/blog/502676 2. How to reverse LinkedList http ...
- Razor基础语法简介
http://blog.csdn.net/pasic/article/details/7072340 Razor的出现,使页面看起更加简洁,Razor的页面后缀为:.cshtml Razor基础语法: ...
- 迷你DVD管理器(Java版)
import java.text.SimpleDateFormat;import java.util.Date;import java.util.Scanner;class Test { pub ...
- @ResponseBody 返回中文乱码问题解决 spingmvc
<!-- UTF8解决乱码问题 --> <bean class="org.springframework.web.servlet.mvc.method.annotation ...
- Null modem接线
1.6 <-> 4 2 <-> 3 3 <-> 2 4 <-> 1.6 5 <-> 5 7 <-> 8 8 <-> ...
- winform中DataGrid控件的宽度设置
最近修改一个win5.0的PDA程式,碰到一个问题.就是给DataGrid控件绑定数据的时候,这个控件的宽度不能调整,有时候数据较长,就显示不全.然后想在程式里自定义它的宽度,设置不成功.然后网上没找 ...
- bootstrap-巨幕、缩略图、警告框
巨幕: <div class="jumbotron"> <div class="container"> <h1>W3Scho ...