首页技术jquery素材?jquery库下载使用

jquery素材?jquery库下载使用

编程之家2026-06-221178次浏览

今天给各位分享jquery素材的知识,其中也会对jquery库下载使用进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

jquery素材?jquery库下载使用

jquery 实现加入购物车功能

参考以下代码:

注意需要导入jquery.js.

<!DOCTYPEhtml>

<html>

<head>

<title>购物车----jQuery</title>

jquery素材?jquery库下载使用

<metacharset="utf-8"/>

<styletype="text/css">

h1{

text-align:center;

}

table{

jquery素材?jquery库下载使用

margin:0auto;

width:60%;

border:2pxsolid#aaa;

border-collapse:collapse;

}

tableth,tabletd{

border:2pxsolid#aaa;

padding:5px;

}

th{

background-color:#eee;

}

</style>

<scripttype="text/javascript"src="./js/jquery.js"></script>

<scripttype="text/javascript">

functionadd_shoppingcart(btn){//将btn(dom)转换为jQuery对象

//先获取商品名字和单价还有库存以备后面使用

var$tds=$(btn).parent().siblings();

//$tds.eq(0)是jQuery对象$tds[0]是DOM对象

varname=$tds.eq(0).html();//string

varprice=$tds.eq(1).html();//string

varstock=$tds.eq(3).html();//string

//查看库存是否还有<=0

if(stock<=0){

return;

}

//无论购物车中是否有该商品,库存都要-1

$tds.eq(3).html(--stock);

//在添加之前确定该商品在购物车中是否存在,若存在,则数量+1,若不存在则创建行

var$trs=$("#goods>tr");

for(vari=0;i<$trs.length;i++){

var$gtds=$trs.eq(i).children();

vargName=$gtds.eq(0).html();

if(name==gName){//若存在

varnum=parseInt($gtds.eq(2).children().eq(1).val());

$gtds.eq(2).children().eq(1).val(++num);//数量+1

//金额从新计算

$gtds.eq(3).html(price*num);

return;//后面代码不再执行

}

}

//若不存在,创建后追加

varli=

"<tr>"+

"<td>"+name+"</td>"+

"<td>"+price+"</td>"+

"<tdalign='center'>"+

"<inputtype='button'value='-'onclick='decrease(this);'/>"+

"<inputtype='text'size='3'readonlyvalue='1'/>"+

"<inputtype='button'value='+'onclick='increase(this);'/>"+

"</td>"+

"<td>"+price+"</td>"+

"<tdalign='center'>"+

"<inputtype='button'value='x'onclick='del(this);'/>"+

"</td>"+

"</tr>";

//追加到#goods后面

$("#goods").append($(li));

//总计功能

total();

}

//辅助方法--单击购物车中的"+""-""x"按钮是找到相关商品所在td,以jQuery对象返回

functionfindStock(btn){

varname=$(btn).parent().siblings().eq(0).html();//获取商品名字

//注意table默认有行分组,若此处使用$("#table1>tr:gt(0)")则找不到任何tr

var$trs=$("#table1>tbody>tr:gt(0)");

for(vari=0;i<$trs.length;i++){

varfName=$trs.eq(i).children().eq(0).html();

if(name==fName){//找到匹配的商品

return$trs.eq(i).children().eq(3);

}

}

}

//增加"+"功能

functionincrease(btn){

//获取该商品库存看是否<=0

var$stock=findStock(btn);

varstock=$stock.html();

if(stock<=0){

return;

}

//库存-1

$stock.html(--stock);

//购物车数据改变

var$td=$(btn).prev();

varnum=parseInt($td.val());//number

//num此时为number类型(在计算时会自动转换为number类型)

$td.val(++num);

//获取单价,再加计算前要先转换为number类型

varprice=parseInt($(btn).parent().prev().html());

$(btn).parent().next().html(num*price);

//总计功能

total();

}

//减少"-"功能

functiondecrease(btn){

//该商品数量=1时候不能再减少

varnum=parseInt($(btn).next().val());

if(num<=1){

return;

}

var$stock=findStock(btn);

//库存+1

varstock=$stock.html();

$stock.html(++stock);

//商品数量-1

$(btn).next().val(--num);

//从新计算金额

varprice=parseInt($(btn).parent().prev().html());

$(btn).parent().next().html(price*num);

//总计功能

total();

}

//"x"删除按钮功能

functiondel(btn){

//将商品数量归还库存

var$stock=findStock(btn);

varstock=parseInt($stock.html());

varnum=parseInt($(btn).parent().prev().prev().children().eq(1).val());

$stock.html(num+stock);

//清空改行商品列表

$(btn).parent().parent().remove();

//总计功能

total();

}

//总计功能

functiontotal(){

//获取所有购物车中的trs

var$trs=$("#goodstr");

varamount=0;

for(vari=0;i<$trs.length;i++){

varmoney=parseInt($trs.eq(i).children().eq(3).html());

amount+=money;

}

//写入总计栏

$("#total").html(amount);

}

</script>

</head>

<body>

<h1>真划算</h1>

<tableid="table1">

<tr>

<th>商品</th>

<th>单价(元)</th>

<th>颜色</th>

<th>库存</th>

<th>好评率</th>

<th>操作</th>

</tr>

<tr>

<td>罗技M185鼠标</td>

<td>80</td>

<td>黑色</td>

<td>5</td>

<td>98%</td>

<tdalign="center">

<inputtype="button"value="加入购物车"onclick="add_shoppingcart(this);"/>

</td>

</tr>

<tr>

<td>微软X470键盘</td>

<td>150</td>

<td>黑色</td>

<td>9028</td>

<td>96%</td>

<tdalign="center">

<inputtype="button"value="加入购物车"onclick="add_shoppingcart(this);"/>

</td>

</tr>

<tr>

<td>洛克iphone6手机壳</td>

<td>60</td>

<td>透明</td>

<td>672</td>

<td>99%</td>

<tdalign="center">

<inputtype="button"value="加入购物车"onclick="add_shoppingcart(this);"/>

</td>

</tr>

<tr>

<td>蓝牙耳机</td>

<td>100</td>

<td>蓝色</td>

<td>8937</td>

<td>95%</td>

<tdalign="center">

<inputtype="button"value="加入购物车"onclick="add_shoppingcart(this);"/>

</td>

</tr>

<tr>

<td>金士顿U盘</td>

<td>70</td>

<td>红色</td>

<td>482</td>

<td>100%</td>

<tdalign="center">

<inputtype="button"value="加入购物车"onclick="add_shoppingcart(this);"/>

</td>

</tr>

</table>

<h1>购物车</h1>

<table>

<thead>

<tr>

<th>商品</th>

<th>单价(元)</th>

<th>数量</th>

<th>金额(元)</th>

<th>删除</th>

</tr>

</thead>

<tbodyid="goods">

</tbody>

<tfoot>

<tr>

<tdcolspan="3"align="right">总计</td>

<tdid="total"></td>

<td></td>

</tr>

</tfoot>

</table>

</body>

</html>最终效果图:

jquery点击一个事件更换图片,在点击更换回来

这是你现在的结构;建议星星图标可以用作背景图片;

<!doctypehtml>

<html>

<head>

<metacharset="utf-8">

<title>无标题文档</title>

<scripttype="text/javascript"src=""></script>

</head>

<body>

<style>

*{margin:0;padding:0;}

ul.stars{display:block;margin:100px100px30px;overflow:hidden;}

ul.starsli{display:block;float:left;padding:04px;cursor:pointer;}

ul.starsliimg{display:block;width:30px;height:30px;}

ul.starsliimg.full{display:none;}

ul.starsli.onimg.empty{display:none;}

ul.starsli.onimg.full{display:block;}

</style>

<script>

$(document).ready(function(e){

$("ul.starsli").click(function(){

$(this).toggleClass("on");

varstars=$("ul.stars").find("li.on").size();

$("input#stars").val(stars);

});

});

</script>

<formmethod="get">

<ulclass="stars">

<li>

<imgclass="empty"src=""/>

<imgclass="full"src=""/>

</li>

<li>

<imgclass="empty"src=""/>

<imgclass="full"src=""/>

</li>

<li>

<imgclass="empty"src=""/>

<imgclass="full"src=""/>

</li>

<li>

<imgclass="empty"src=""/>

<imgclass="full"src=""/>

</li>

<li>

<imgclass="empty"src=""/>

<imgclass="full"src=""/>

</li>

</ul>

<inputtype="hidden"id="stars"name="stars"/>

<inputtype="submit"value="提交"style="margin:0100px;">

</form>

</body>

</html>最好的方式是把图片处理一下作为ul的背景图,通过点击li获取索引值来改变ul的背景图片位置;不能上传附件了。。还是上代码吧。。

<!DOCTYPEHTML>

<html>

<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>

<metahttp-equiv="X-UA-Compatible"content="IE=EmulateIE7"/>

<metaname="keywords"content=""/>

<metaname="description"content=""/>

<title>评价</title>

<scripttype="text/javascript"src=""></script>

<script>

$(document).ready(function(){

//星级评分

$("formpspan.radiolabel.radio").click(function(){

$(this).parent("span.radio").css("background-position-y",-($(this).index()*19)+"px");

});

});

</script>

<style>

*{margin:0;padding:0;}

formp{display:block;overflow:hidden;padding:10px20px;}

formplabel{display:block;height:36px;line-height:36px;color:#444;font-size:14px;float:left;}

formpspan.radio{display:block;width:150px;height:19px;background:url(stars.png)left0pxno-repeat;float:left;margin:8px00;}

formpinput.radio{display:none;}

formplabel.radio{width:20%;height:100%;margin:0;cursor:pointer;}

forminput.btn{display:block;width:210px;height:36px;line-height:36px;*line-height:normal;color:#fff;font-size:15px;background:#ffb81f;border:0;border-radius:6px;cursor:pointer;float:left;margin-top:10px;}

</style>

<body>

<form>

<p>

<label>服务态度:</label>

<spanclass="radio">

<inputclass="radio"type="radio"name="star1"value="0"checked/>

<labelclass="radio"for="star11"></label>

<labelclass="radio"for="star12"></label>

<labelclass="radio"for="star13"></label>

<labelclass="radio"for="star14"></label>

<labelclass="radio"for="star15"></label>

<inputid="star11"class="radio"type="radio"name="star1"value="1"/>

<inputid="star12"class="radio"type="radio"name="star1"value="2"/>

<inputid="star13"class="radio"type="radio"name="star1"value="3"/>

<inputid="star14"class="radio"type="radio"name="star1"value="4"/>

<inputid="star15"class="radio"type="radio"name="star1"value="5"/>

</span>

</p>

<p>

<label>运输速度:</label>

<spanclass="radio">

<inputclass="radio"type="radio"name="star2"value="0"checked/>

<labelclass="radio"for="star21"></label>

<labelclass="radio"for="star22"></label>

<labelclass="radio"for="star23"></label>

<labelclass="radio"for="star24"></label>

<labelclass="radio"for="star25"></label>

<inputid="star21"class="radio"type="radio"name="star2"value="1"/>

<inputid="star22"class="radio"type="radio"name="star2"value="2"/>

<inputid="star23"class="radio"type="radio"name="star2"value="3"/>

<inputid="star24"class="radio"type="radio"name="star2"value="4"/>

<inputid="star25"class="radio"type="radio"name="star2"value="5"/>

</span>

</p>

<p>

<label>货款发放:</label>

<spanclass="radio">

<inputclass="radio"type="radio"name="star3"value="0"checked/>

<labelclass="radio"for="star31"></label>

<labelclass="radio"for="star32"></label>

<labelclass="radio"for="star33"></label>

<labelclass="radio"for="star34"></label>

<labelclass="radio"for="star35"></label>

<inputid="star31"class="radio"type="radio"name="star3"value="1"/>

<inputid="star32"class="radio"type="radio"name="star3"value="2"/>

<inputid="star33"class="radio"type="radio"name="star3"value="3"/>

<inputid="star34"class="radio"type="radio"name="star3"value="4"/>

<inputid="star35"class="radio"type="radio"name="star3"value="5"/>

</span>

</p>

<p>

<inputclass="btn"type="submit"value="提交"/>

</p>

</form>

</body>

</html>附上图片素材

jquery素材的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于jquery库下载使用、jquery素材的信息别忘了在本站进行查找哦。

iframe html html页面魔兽世界 官网?wow官网