Jquery
jQuery是一个快速,小巧,功能丰富的JavaScript库。
它使诸如HTML文档遍历和操作,事件处理,动画和Ajax等事情变得简单得多,
它具有可在多种浏览器中工作的易于使用的API。
结合多功能性和可扩展性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery</title>
<style type="text/css">
body{
margin: 0;
padding: 0;
background-color: black;
color: white;
}
body div{
background-color: red;
margin: 50px auto;
text-align: center;
}
.item{
width: 100px;
height: 100px;
line-height: 100px;
}
</style>
</head>
<body>
<div class="item">1</div>
<div class="item">2</div>
</body>
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<script type="text/javascript">
$(".item").css("color", "purple");
$(".item").css({"color": "white", "background-color": "purple", "border": "1px white solid"});
$(".item").css({"width": function(index, oldValue){
console.log(index, oldValue);
return (index + 1) * 100;
}, "height": function(index, oldValue){
console.log(index, oldValue);
return (index + 1) * 100;
}, "line-height": function(index, oldValue){
console.log(index, oldValue);
return (index + 1) * 100 + "px";
}});
console.log($(".item").css("width"));
$("div").text("hello world~");
var item = document.getElementsByClassName("item")[0];
$(item);
$(".item");
$(".item")[1].innerHTML = "也是JQ 对象转原生对象";
$(".item").get(0).innerHTML = "JQ 转原生";
$(".item").eq(0).html("这是第一个");
$(".item").css("background-color", "purple").parent().css("border", "5px red solid").end().css("height", "200px");
$("<div></div>").html("新的 JQ 对象").appendTo($("body"));
$(".item").prop("title", "这是提示");
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery2</title>
<style type="text/css">
.redDiv{
width: 100px;
height: 100px;
background-color: red;
}
</style>
</head>
<body>
<div class="redDiv"></div>
<input type="button" value="显示">
</body>
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<script type="text/javascript">
$(":button").click(function(){
$(".redDiv").slideUp(1000);
});
$("div").reset(function(){
})
$("from").on("submit", f1);
$("from").on("submit", f2);
$("from").off();
$("from").off("click");
$("from").off("click", f1);
function f1(){
}
function f2(){
}
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>购物车</title>
<style type="text/css">
table{
margin: 20px auto;
text-align: center;
}
</style>
</head>
<body>
<table border="1" width="800" height="500">
<tr height="100">
<td>
<input type="checkbox" class="checkboxall">全选
</td>
<td>商品</td>
<td>单价</td>
<td>数量</td>
<td>小计</td>
<td>操作</td>
</tr>
<tr class="commodity">
<td>
<input type="checkbox" class="checkbox">
</td>
<td>佳能</td>
<td class="price">100</td>
<td>
<input type="button" value="-" class="minus" />
<input type="text" value="0"/>
<input type="button" value="+" class="add" />
</td>
<td class="subtotal">0</td>
<td>
<input type="button" value="删除" class="delete" />
</td>
</tr>
<tr class="commodity">
<td>
<input type="checkbox" class="checkbox">
</td>
<td>佳能</td>
<td class="price">200</td>
<td>
<input type="button" value="-" class="minus" />
<input type="text" value="0"/>
<input type="button" value="+" class="add" />
</td>
<td class="subtotal">0</td>
<td>
<input type="button" value="删除" class="delete" />
</td>
</tr>
<tr class="commodity">
<td>
<input type="checkbox" class="checkbox">
</td>
<td>佳能</td>
<td class="price">300</td>
<td>
<input type="button" value="-" class="minus" />
<input type="text" value="0"/>
<input type="button" value="+" class="add" />
</td>
<td class="subtotal">0</td>
<td>
<input type="button" value="删除" class="delete" />
</td>
</tr>
<tr height="100">
<td colspan="6">
<input type="button" value="删除所有" class="deleteall" />
已选择商品<span class="pitch">0</span>
合计:¥<span class="total">0</span>
</td>
</tr>
</table>
</body>
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<script type="text/javascript">
$(".add").click(function(){
var num = $(this).prev().val();
$(this).prev().val(++num);
$(this).parent().next().text(num * $(this).parent().prev().text());
if ($(this).parent().prev().prev().prev()) {}
});
$(".minus").click(function(){
var num = $(this).next().val();
if (num > 0) {
$(this).next().val(--num);
$(this).parent().next().text(num * $(this).parent().prev().text());
}
});
$(".delete").click(function(){
$(this).parent().parent().remove();
});
$(".deleteall").click(function(){
$(".delete").parent().parent().remove();
});
$(".checkboxall").click(function(){
if ($(this).prop("checked") == true) {
$(".checkbox").prop("checked", true);
$(".pitch").text(3);
} else{
$(".checkbox").prop("checked", false);
$(".pitch").text(0);
}
});
$(".checkbox").click(function(){
var num = $(".pitch").text();
if ($(this).prop("checked") == true) {
$(".pitch").text(++num);
} else{
$(".pitch").text(--num);
}
});
</script>
</html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Document</title>
<link rel="stylesheet" type="text/css" href="购物车.css">
<link rel="stylesheet" type="text/css" href="reset.css">
</head>
<body>
<table class="box" border="1">
<tr class="header">
<td width="90">
<input type="checkbox" id="selectAll" />
<label for="selectAll">全选</label>
</td>
<td width="230">商品</td>
<td width="173">单价</td>
<td width="127">数量</td>
<td width="197">小计</td>
<td>操作</td>
</tr>
<tr>
<td class="check">
<input type="checkbox" class="checkt" />
</td>
<td class="proName">
<img src="" alt="" />
<span>佳能</span>
</td>
<td class="proPirce">
<span>100</span>
</td>
<td class="proCount">
<input type="button" value="-" class="ys" />
<input type="text" class="count" value="0" />
<input type="button" value="+" class="ys"/>
</td>
<td class="proMoney">
<span>0</span>
</td>
<td>
<input type="button" value="删除" class="proDel" />
</td>
</tr>
<tr>
<td class="check">
<input type="checkbox" class="checkt"/>
</td>
<td class="proName">
<img src="" alt="" />
<span>佳能</span>
</td>
<td class="proPirce">
<span>200</span>
</td>
<td class="proCount">
<input type="button" value="-" class="ys" />
<input type="text" class="count" value="0" />
<input type="button" value="+" class="ys"/>
</td>
<td class="proMoney">
<span>20</span>
</td>
<td>
<input type="button" value="删除" class="proDel" />
</td>
</tr>
<tr>
<td class="check">
<input type="checkbox" class="checkt" />
</td>
<td class="proName">
<img src="" alt="" />
<span>佳能</span>
</td>
<td class="proPirce">
<span>300</span>
</td>
<td class="proCount">
<input type="button" value="-" class="ys" />
<input type="text" class="count" value="0" />
<input type="button" value="+" class="ys"/>
</td>
<td class="proMoney">
<span>10</span>
</td>
<td>
<input type="button" value="删除" class="proDel" />
</td>
</tr>
<tr class="footer">
<td colspan="6">
<div class="delAll">删除所有</div>
<div class="proTotal">已选商品<span>0</span>件</div>
<div class="totalPirces">合计:¥<span>0</span></div>
</td>
</tr>
</table>
</body>
<script type="text/javascript" src="jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$("#selectAll").click(function(){
$(".checkt").prop("checked", this.checked);
change();
})
$(".checkt").click(function(){
change();
})
$(".ys").click(function(){
var ys = this;
var count = 0;
$(this).siblings(".count").val(function(index, oldValue){
count = Number(oldValue) + Number(ys.value + 1)
return count;
})
var res = count * $(this).parents("tr").find(".proPirce span").html();
$(this).parents("tr").find(".proMoney span").html(res);
change();
})
$(".proDel").click(function(){
$(this).parents("tr").remove();
change();
})
$(".delAll").click(function(){
$(".checkt:checked").parents("tr").remove();
change();
$("#selectAll").prop("checked", false);
})
function change(){
var res = $(".checkt:checked").length == $(".checkt").length
$("#selectAll").prop("checked", res);
var all = 0;
$(".checkt:checked").parents("tr").find(".proMoney span").each(function(index,obj){
all += Number(obj.innerHTML);
})
$(".totalPirces span").html(all);
var count = $(".checkt:checked").length;
$(".proTotal span").html(count);
}
</script>
</html>
table.box{
width: 900px;
height:350px;
margin: 50px auto;
border-color: #a7cbff;
border-collapse: collapse;
text-align: center;
}
.box tr.header td{
height: 32px;
background-color: #e2f2ff;
border-top: 3px solid #a7cbff;
}
.box tr.footer td{
height: 50px;
background-color: #eaeaea;
}
.box tr.footer div{
float: left;
}
.box tr.footer .delAll{
margin: 0px 500px 0px 50px;
}
.box tr.footer .proTotal{
margin-right: 50px;
}
div span{
color: red;
}
.box td .count{
width: 50px;
}
.box td input{
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
body{
margin: 0;
padding: 0;
}
.box{
width: 960px;
margin: 0 auto;
padding: 0;
border: 1px white solid;
}
.screen, .stature, .age, .sex{
width: 920px;
height: 30px;
margin: 0 20px;
line-height: 30px;
border-bottom: 1px #FFFFFF55 solid;
}
.screen{
margin-top: 10px;
}
.screen div{
float: left;
}
.stature div, .age div, .sex div{
float: left;
padding: 0 20px 0 0;
}
.staturenum, .agenum, .sexnum{
padding: 0 10px 0 10px;
}
table{
margin: 10px 20px 0;
text-align: center;
}
td{
width: 100px;
height: 40px;
}
</style>
</head>
<body>
<div class="box">
<div class="screen">
<div class="allres">全部结果</div>
<div class="people"> > "人"</div>
</div>
<div class="stature">
<div>身高:</div>
<div class="staturenum" value="1">160以下</div>
<div class="staturenum" value="2">160-180</div>
<div class="staturenum" value="3">180以上</div>
</div>
<div class="age">
<div>年龄:</div>
<div class="agenum" value="1">18以下</div>
<div class="agenum" value="2">18-30</div>
<div class="agenum" value="3">30以上</div>
</div>
<div class="sex">
<div class="sexnum">性别:</div>
<div class="sexnum" value="1">男</div>
<div class="sexnum" value="2">女</div>
</div>
<table border="1">
<tr>
<td>姓名</td>
<td>身高</td>
<td>年龄</td>
<td>性别</td>
</tr>
</table>
</div>
</body>
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<script type="text/javascript">
var list = '[{"name":"1", "stature":"159", "age":"17", "sex":"男"}, {"name":"2", "stature":"159", "age":"20", "sex":"男"}, {"name":"3", "stature":"159", "age":"35", "sex":"男"}, {"name":"4", "stature":"159", "age":"17", "sex":"女"}, {"name":"5", "stature":"159", "age":"20", "sex":"女"}, {"name":"6", "stature":"159", "age":"35", "sex":"女"}, {"name":"7", "stature":"175", "age":"17", "sex":"男"}, {"name":"8", "stature":"175", "age":"20", "sex":"男"}, {"name":"9", "stature":"175", "age":"35", "sex":"男"}, {"name":"10", "stature":"175", "age":"17", "sex":"女"}, {"name":"11", "stature":"175", "age":"20", "sex":"女"}, {"name":"12", "stature":"175", "age":"35", "sex":"女"}, {"name":"13", "stature":"185", "age":"17", "sex":"男"}, {"name":"14", "stature":"185", "age":"20", "sex":"男"}, {"name":"15", "stature":"185", "age":"35", "sex":"男"}, {"name":"16", "stature":"185", "age":"17", "sex":"女"}, {"name":"17", "stature":"185", "age":"20", "sex":"女"}, {"name":"18", "stature":"185", "age":"35", "sex":"女"}, {"name":"19", "stature":"178", "age":"22", "sex":"男"}, {"name":"20", "stature":"178", "age":"22", "sex":"女"}]';
var json = $.parseJSON(list);
$(json).each(function(){
$("table").append("<tr><td>" + this.name + "</td><td>" + this.stature + "</td><td>" + this.age + "</td><td>" + this.sex + "</td></tr>");
});
$(".staturenum").click(function(){
switch($(this).attr("value")){
case "1":
$("tr:gt(0) td:nth-child(2)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() > 160) {
$(this).parent().css("display", "none");
}
})
break;
case "2":
$("tr:gt(0) td:nth-child(2)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() < 160 || $(this).text() > 180) {
$(this).parent().css("display", "none");
}
})
break;
case "3":
$("tr:gt(0) td:nth-child(2)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() < 180) {
$(this).parent().css("display", "none");
}
})
break;
}
$(this).parent().css("display", "none");
$(".people").append("<div class=" + "nbsp" +"> > </div>").append("<div class=" + "condition value=" + "1" + ">" + $(this).text() + "</div>").append("<div class=" + "miss" + "> ✘ </div>");
miss();
});
$(".agenum").click(function(){
switch($(this).attr("value")){
case "1":
$("tr:gt(0) td:nth-child(3)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() > 18) {
$(this).parent().css("display", "none");
}
})
break;
case "2":
$("tr:gt(0) td:nth-child(3)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() < 18 || $(this).text() > 30) {
$(this).parent().css("display", "none");
}
})
break;
case "3":
$("tr:gt(0) td:nth-child(3)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() < 30) {
$(this).parent().css("display", "none");
}
})
break;
}
$(this).parent().css("display", "none");
$(".people").append("<div class=" + "nbsp" +"> > </div>").append("<div class=" + "condition value=" + "2" + ">" + $(this).text() + "</div>").append("<div class=" + "miss" + "> ✘ </div>");
miss();
});
$(".sexnum").click(function(){
switch($(this).attr("value")){
case "1":
$("tr:gt(0) td:nth-child(4)").each(function(index, obj){
if ($(this).text() == "女") {
$(this).parent().css("display", "none");
}
})
break;
case "2":
$("tr:gt(0) td:nth-child(4)").each(function(index, obj){
if ($(this).text() == "男") {
$(this).parent().css("display", "none");
}
})
break;
}
$(this).parent().css("display", "none");
$(".people").append("<div class=" + "nbsp" +"> > </div>").append("<div class=" + "condition value=" + "3" + ">" + $(this).text() + "</div>").append("<div class=" + "miss" + "> ✘ </div>");
miss();
});
$(".allres").click(function(){
$(".stature").css("display", "block");
$(".sex").css("display", "block");
$(".age").css("display", "block");
$(".condition").remove();
$(".miss").remove();
$(".nbsp").remove();
$("tr").css("display", "table-row");
});
function miss(){
$(".miss").click(function(){
if ($(this).prev().attr("value") == 1) {
$(".stature").css("display", "block");
switch($(this).prev().text()){
case "160以下":
$("tr:gt(0) td:nth-child(2)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() > 160) {
$(this).parent().css("display", "table-row");
}
})
break;
case "160-180":
$("tr:gt(0) td:nth-child(2)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() < 160 || $(this).text() > 180) {
$(this).parent().css("display", "table-row");
}
})
break;
case "180以上":
$("tr:gt(0) td:nth-child(2)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() < 180) {
$(this).parent().css("display", "table-row");
}
})
break;
}
} else if ($(this).prev().attr("value") == 2) {
$(".age").css("display", "block");
switch($(this).prev().text()){
case "18以下":
$("tr:gt(0) td:nth-child(3)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() > 18) {
$(this).parent().css("display", "table-row");
}
})
break;
case "18-30":
$("tr:gt(0) td:nth-child(3)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() < 18 || $(this).text() > 30) {
$(this).parent().css("display", "table-row");
}
})
break;
case "30以上":
$("tr:gt(0) td:nth-child(3)").each(function(index, obj){
console.log($(this).text());
if ($(this).text() < 30) {
$(this).parent().css("display", "table-row");
}
})
break;
}
} else if ($(this).prev().attr("value") == 3) {
$(".sex").css("display", "block");
switch($(this).prev().text()){
case "男":
$("tr:gt(0) td:nth-child(4)").each(function(index, obj){
if ($(this).text() == "女") {
$(this).parent().css("display", "table-row");
}
})
break;
case "女":
$("tr:gt(0) td:nth-child(4)").each(function(index, obj){
if ($(this).text() == "男") {
$(this).parent().css("display", "table-row");
}
})
break;
}
}
$(this).prev().remove();
$(this).prev().remove();
$(this).remove();
});
}
</script>
</html>
http://blog.csdn.net/huzongnan/article/list