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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
<html>
<head>
<title></title>
<script type="text/javascript">
<!--
var monObjet = function()
{
this.monDiv=document.createElement("div");
document.body.appendChild(this.monDiv);
}
monObjet.prototype={
getObjet : function()
{
return this.monDiv;
}
,
setStyle : function(style, valeur)
{
var code = "monDiv.style."+style+"='"+valeur+"';";
var ff = new Function("monDiv",code);
ff(this.monDiv);
}
,
setId : function(id)
{
this.monDiv.id = id;
}
,
getId : function()
{
return this.monDiv.id;
}
,
setClic : function()
{
this.monDiv.onclick = function(){alert("id= "+this.id);};
}
}
function test()
{
var obj = new monObjet();
obj.setId("idDiv");
obj.setStyle("border","1px solid #AAAAAA");
obj.setStyle("height","200px");
obj.setStyle("width","200px");
obj.setClic();
}
//-->
</script>
</head>
<body onload="test()">
</body>
</html> |
Partager