javascript實(shí)現(xiàn)checkbox復(fù)選框?qū)嵗a
本文實(shí)例介紹了javascript實(shí)現(xiàn)checkbox復(fù)選框?qū)嵗a以及對(duì)checkbox復(fù)選框進(jìn)行美化操作,分享給大家供大家參考,具體內(nèi)容如下
1、checkbox復(fù)選框進(jìn)行美化操作
復(fù)選框默認(rèn)外表的美觀度差強(qiáng)人意,能夠滿足美觀度要求不高的頁(yè)面,但是如果對(duì)于頁(yè)面要求較為精致,那可能就過(guò)于勉強(qiáng)了,下面就一段對(duì)復(fù)選框進(jìn)行美化的代碼實(shí)例,希望能夠給大家?guī)?lái)一定的幫助。
代碼實(shí)例如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<title>checkbox復(fù)選框</title>
<style type="text/css">
.CheckBoxClass{display:none;}
.CheckBoxLabelClass{
background:url("mytest/jQuery/UnCheck.png") no-repeat;
padding-left:30px;
padding-top:3px;
margin:5px;
height:28px;
width:150px;
display:block;
}
.CheckBoxLabelClass:hover{text-decoration:underline;}
.LabelSelected{background:url("mytest/jQuery/Check.png") no-repeat;}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".CheckBoxClass").change(function(){
if($(this).is(":checked")){
$(this).next("label").addClass("LabelSelected");
}
else{
$(this).next("label").removeClass("LabelSelected");
}
});
})
</script>
</head>
<body>
<div>
<input id="CheckBox1" type="checkbox" class="CheckBoxClass"/>
<label id="Label1" for="CheckBox1" class="CheckBoxLabelClass">腳本之家一</label>
<input id="CheckBox2" type="checkbox" class="CheckBoxClass"/>
<label id="Label2" for="CheckBox2" class="CheckBoxLabelClass">腳本之家二</label>
</div>
</body>
</html>
2、checkbox復(fù)選框全選和取消全選實(shí)例代碼
關(guān)于復(fù)選框的全選和不全選是非常常見(jiàn)的操作,本章節(jié)分享一段代碼實(shí)例,能夠?qū)崿F(xiàn)多種選中和取消選中功能。
代碼實(shí)例如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<title>腳本之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$("document").ready(function(){
$("#all").click(function(){
if(this.checked)
{
$("input[name='checkbox']").each(function(){this.checked=true;});
$("#btn1").attr("value","反選");
}
else
{
$("input[name='checkbox']").each(function(){this.checked=false;});
$("#btn1").attr("value","全選");
}
});
$("#btn1").click(function(){
$("[name='checkbox']").attr("checked",'true');
})
$("#cancel").click(function(){
$("[name='checkbox']").removeAttr("checked");
})
$("#jishu").click(function(){
$("[name='checkbox']:even").attr("checked",'true');
})
$("#fanxuan").click(function(){
$("[name='checkbox']").each(function(){
if($(this).attr("checked"))
{
$(this).removeAttr("checked");
}
else
{
$(this).attr("checked",'true');
}
})
})
$("#get").click(function(){
var str="";
$("[name='checkbox'][checked]").each(function(){
str+=$(this).val()+"/r/n";
})
alert(str);
})
})
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input type="checkbox" id="all" name="all">
<input type="button" id="btn1" value="全選">
<input type="button" id="cancel" value="取消全選">
<input type="button" id="jishu" value="選中所有奇數(shù)">
<input type="button" id="fanxuan" value="反選">
<input type="button" id="get" value="獲得選中的所有值">
<br>
<input type="checkbox" name="checkbox" value="腳本之家一">
腳本之家一
<input type="checkbox" name="checkbox" value="腳本之家二">
腳本之家二
<input type="checkbox" name="checkbox" value="腳本之家三">
腳本之家三
<input type="checkbox" name="checkbox" value="腳本之家四">
腳本之家四
<input type="checkbox" name="checkbox" value="腳本之家五">
腳本之家五
<input type="checkbox" name="checkbox" value="腳本之家六">
腳本之家六
<input type="checkbox" name="checkbox" value="腳本之家七">
腳本之家七
<input type="checkbox" name="checkbox" value="腳本之家八">
腳本之家八
</form>
</body>
</html>
以上就是關(guān)于checkbox復(fù)選框的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
相關(guān)文章
JS for循環(huán)中i++ 和 ++i的區(qū)別介紹
這篇文章主要介紹了JS for循環(huán)中i++ 和 ++i的區(qū)別介紹的相關(guān)資料,需要的朋友可以參考下2016-07-07
js css 實(shí)現(xiàn)遮罩層覆蓋其他頁(yè)面元素附圖
實(shí)現(xiàn)遮罩層的方法有很多,但大多都是使用js css來(lái)實(shí)現(xiàn)的,本例也實(shí)現(xiàn)一個(gè),效果還不錯(cuò),喜歡的朋友可以感受下2014-09-09
微信小程序使用navigator實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)功能
本周學(xué)習(xí)了navigtor到導(dǎo)航組件,目前我想使用navigtor組件實(shí)現(xiàn)跳轉(zhuǎn)以及返回功能,下面這篇文章主要給大家介紹了關(guān)于微信小程序使用navigator實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)功能的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08
簡(jiǎn)單實(shí)現(xiàn)輪播圖效果的實(shí)例
下面小編就為大家?guī)?lái)一篇簡(jiǎn)單實(shí)現(xiàn)輪播圖效果的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-07-07
微信小程序天氣預(yù)報(bào)功能實(shí)現(xiàn)(支持自動(dòng)定位,附源碼)
對(duì)于一個(gè)經(jīng)常出門(mén)在外的人,關(guān)注天氣是至關(guān)重要的,下面這篇文章主要給大家介紹了關(guān)于微信小程序天氣預(yù)報(bào)功能實(shí)現(xiàn)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),支持自動(dòng)定位,需要的朋友可以參考下2022-04-04
javascript計(jì)算用戶打開(kāi)網(wǎng)頁(yè)的停留時(shí)間
本文介紹了javascript計(jì)算用戶打開(kāi)網(wǎng)頁(yè)的停留時(shí)間,大家參考使用吧2014-01-01

