Cherish_Now

导航

jq封装

<div id='container' class='container'>盒子</div>
<button onClick="f()" >test按钮</button>

class JQuery {
	constructor(name){
		this.doc = document.getElementById(name);
	}
	html(html){
		this.doc.innerHTML = html;
		return this;
	}
	color(color){
		this.doc.style.backgroundColor = color;
		return this
	}
}
window.$ = function (name) {
	return new JQuery(name);
}
function f(){
	$('container').html('改变了').color('#ade')
}

效果:

posted on 2019-03-25 18:13  Cherish_Now  阅读(153)  评论(0编辑  收藏  举报