<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <link rel="stylesheet" type="text/css" href="css/style.css"> <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script> <script> function Person(name) { this.name=name; } Person.prototype.showName=function (btn,pop,bg) { $(function(){ $(btn).on("click", function(){ $(pop).show(); }); $(bg).on("click", function(){ $(pop).hide(); }); }) }; function Worker(name, job) { //this->new出来的Worker对象 //构造函数伪装 调用父级的构造函数——为了继承属性 Person.call(this, name); this.job=job; } //通过原型来继承父级的方法 Worker.prototype=Person.prototype; var oW1=new Worker(); oW1.showName("button",".pop-box",".bg"); </script> </head> <body> <button>button01</button> <div class="pop-box"> <div class="bg"></div> <div class="pop"></div> </div> </body> </html>
时间: 2024-10-06 16:48:26