Bonjour,

L'évènement du code suivnat ne fonctionne pas.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
40
41
42
function colorPicker () {
	var cp;
 
	this.createColorPicker=function(){
		var imgBase = 'creating/';
 
			//On crée la fenêtre contenant le sélecteur de couleur
			var CE1=null;
			CE1=document.createElement("div");
			CE1.id='ColorPicker';
			document.getElementById("act").insertBefore(CE1,null);
			var txt=document.createTextNode("Select color : ");
			document.getElementById("ColorPicker").appendChild(txt);
	}
 
	this.attachColorPicker=function()
	{
		 this.createColorPicker();
		 this.SetId()
		 this.SetEvents();
	}
 
	this.SetEvents=function(){
 
		addEvt(this.cp.ColorPicker,"click",this.hideColorPicker);
	}
 
	this.SetId=function(){
		this.cp.ColorPicker=document.getElementById("ColorPicker");
	}
 
	this.addEvt=function(o,e,f){ 
			if(window.addEventListener) o.addEventListener(e, f, false); 
				else o.attachEvent("on"+e,f);
	}
 
	this.hideColorPicker=function(){
		this.cp.ColorPicker.style.display  = 'none';
		alert("fin");
		return false;
	}
}
Le code html est
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
<html>
<head>
<script language="JavaScript" type="text/javascript" src="colorpicker.js"></script>
<style>#ColorPicker{width:500px;height:300px;border:1px solid red;position:absolute;left:100px;}</style>
</head>
<body>
<button id="act" onclick="var colorp=new colorPicker();colorp.attachColorPicker();">test</button>
</body>
</html>
Je pense que this.cp.ColorPicker est null ou n'est pas défini comme objet (via la méthode SetID().
J'utilise SetId car ColorPicker va inclure d'autres éléments donc je voulais simplifier le code !

Pourquoi ce défaut?

Merci