-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo12.js
60 lines (33 loc) · 1.05 KB
/
demo12.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Created by Administrator on 2017/8/28 0028.
*/
//装饰着模式
//在不改变原对象的基础上,通过对其进行包装拓展(添加属性或者方法)使原有对象可以满足用户的
//更加复杂的需求
//情况一
var telInput = document.getElementById("tel_input");
var telWarnText = document.getElementById("tel_wan_text");
input.onclick = function(){
telWarnText.style.display = "inline-block"
}
//情况二
var telInput = document.getElementById("tel_input");
var telWarnText = document.getElementById("tel_wan_text");
var telDemoText = document.getElementById("tel_demo_text")
input.onclick = function(){
telWarnText.style.display = "inline-block"
telDemoText.style.display = "none"
}
//装饰者
var decorator = function(input,fn){
var input = document.getElementById(input)
if(typeof input.onclick === "function"){
var oldClicFn = input.onclick;
input.onclick = function(){
oldClikcFn();
fn()
}
}else{
input.onlick = fn;
}
}