jQuery object extension method

<! DOCTYPE HTML > 
<HTML>
<head>
<Meta charset = "UTF-. 8" >
<title> 01-expansion method of the jQuery object </ title>
<Script the src = "../js/jquery-3.3.1 .min.js " type = " text / JavaScript " charset = " UTF-. 8 " > </ Script>
<Script type = " text / JavaScript " > // widget using jquery object is added to the two methods jq check () selected All checkbox uncheck () uncheck all boxes // 1, the definition of the object jquery plugins $. the Fn. Extend ({ // define a check () method, all jquery object can call this method to check: function () { the this.prop("checked",true);






},
uncheck:function () {
this.prop("checked",false);
}
});
$(function () {
$("#btn-check").click(function () {
// $("#btn-check").check();
$("input[type='checkbox']").check();
});

$("#btn-uncheck").click(function () {
$("input[type='checkbox']").uncheck();
});
});

</script>
</head>
<body>
<input id="btn-check" type="button" value="点击选中复选框" onclick="checkFn()">
<input id="btn-uncheck" type="button" value="点击取消复选框选中" onclick="uncheckFn()">
<br/>
<input type="checkbox" value="football">足球
<input type="checkbox" value="basketball">篮球
<input type="checkbox" value="volleyball">排球

</body>
</html>

Guess you like

Origin www.cnblogs.com/newcityboy/p/11525183.html