$(document).ready(function () {
//實(shí)現(xiàn)全選反選
$("input[id='selectall']").on('click', function() {
$("input[name='chk']").prop("checked", $(this).prop('checked'));
})
$("#div1 input[name='chk']").on('click', function() {
//當(dāng)選中的長度等于checkbox的長度的時(shí)候,就讓控制全選反選的checkbox設(shè)置為選中,否則就為未選中
if($("#div1 input[name='chk']").length === $("#div1 input:checked").length) {
$("input[id='selectall']").prop("checked", true);
} else {
$("input[id='selectall']").prop("checked", false);
}
})
<input type="checkbox" id="selectall">one <br>
<div id="div1">
<input type="checkbox" name="chk">two <br>
<input type="checkbox" name="chk">three <br>
<input type="checkbox" name="chk">four <br>
<input type="checkbox" name="chk">five <br>
<input type="checkbox" name="chk">six <br>
</div>
奇偶變色
$(document).ready(function () {
$("tr:even").css("background-color","red");
$("tr:odd").css("background-color","blue");
$("tr:last").css("font-weight","bold");
$("tr:eq(1)").css("background-color","green");
$("tr:eq(2)").css("background-color","orange");
$("td:even").css("opacity","0.2")
})
圖片切換
$(function () {
$("#btn1").click(function () {
$("#img1").attr("src","images/xiammisuzu1.jpg");
});
$("#btn2").click(function () {
$("#img1").attr("src","images/xiaomishuzu2.jpg");
});
$("#btn3").click(function () {
$("#img1").attr("src","images/xiaomishuzu3.jpg");
});
$("#btn4").click(function () {
$("#img1").removeAttr("src");
});
$("#btn5").click(function () {
$("#img1").toggle(5000,"linear",function () {
alert("圖片切換完成1");
});
/*$("#img1").toggle(function () {
alert("圖片切換完成1");
});*/
});
$("#btn6").click(function () {
$("#img1").toggle(8000,"swing",function () {
alert("圖片切換完成2");
})
})
});
<img src="images/xiaomishuzu4.jpg" width="610" height="300" id="img1"><br>
<input type="button" id="btn1" value="切到圖片1">
<input type="button" id="btn2" value="切到圖片2">
<input type="button" id="btn3" value="切到圖片3">
<input type="button" id="btn4" value="移除圖片">
<input type="button" id="btn5" value="隱藏/顯示圖片1">
<input type="button" id="btn6" value="隱藏/顯示圖片2">
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者