changestyle是自定义的构造函数,再通过原型添加方法的函数。
实例化对象,导入json参数,和创建cs,调用原型添加的方法函数
过渡,先熟悉记忆
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>title</title> <style> div { width: 300px; height: 200px; background-color: red; } </style> </head> <body> <input type="button" value="显示效果" id="btn" /> <div id="dv"></div> <script src="common.js"></script> <script> function changestyle(btnobj, dvobj, json) { this.btnobj = btnobj; this.dvobj = dvobj; this.json = json; } changestyle.prototype.init = function () { //点击按钮,改变div多个样式属性值 var that = this; this.btnobj.onclick = function () { for (var key in that.json) { that.dvobj.style[key] = that.json[key]; } }; }; //实例化对象 var json = { "width": "500px", "height": "300px", "backgroundcolor": "blue" } var cs = new changestyle(my$("btn"), my$("dv"), json); cs.init();//调用方法 </script> </body> </html>
如对本文有疑问, 点击进行留言回复!!
Parallels Desktop v15.1.4-47270 商业版下载 Mac安装Windows首选虚拟机
关于LPC824Lite开发板下载程序时提示"Invalid ROM Table"
MySQL 5.7 关于 JSON 类型的子集Key/Value获取方法分享
javascript从入门到跑路-----小文的js学习笔记(19)------- js的垃圾回收机制
网友评论