jquery 自定义函数不工作,望大神支招
程序如下:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="scripts/jquery-3.1.1.js"></script>
<script>
$(() => {
$.fn.disable = function () {
return this.each(function () {
if (this.disabled == null) this.disabled = true;
});
}
$("#myp").children().disable();
});
</script>
</head>
<body id="myBody">
<p id="myp">
<input type="button" value="Button1" />
<input type="button" value="Button2" />
<input type="button" value="Button3" />
<input type="button" value="Button4" />
<input type="button" value="Button5" />
</p>
</body>
</html>
本意是定义一个自定义函数 $.fn.disable, 目的是把所有选择出来的input全都disable掉, 但是在使用的时候发现根本不好使,$("#myp").children().disable();
我哪里写错了?都是照着教科书做的
多谢