<HTML>
<HEAD>
<TITLE> Steki's Dynamic Button Making </TITLE>
<script>
var StekiUtil={
fid:function(id)
{
return document.getElementById(id);
}
, addEventListenerById:function( objId, evtName, fuc )
{
StekiUtil.addEventListenerByObject(StekiUtil.fid(objId), evtName, fuc );
}
, addEventListenerByObject:function( obj, evtName, fuc )
{
if (obj.addEventListener)
{
obj.addEventListener(evtName, fuc, false);
}
else
{
obj.attachEvent("on" + evtName, fuc);
}
if(evtName=="click" && obj){
obj.style.cursor=obj.addEventListener?"pointer":"hand";
}
}
}
function MyButton(id, func ){
this.myButton = document.createElement("input");
this.myButton.name = id;
this.myButton.value = id;
this.myButton.type = "button";
StekiUtil.fid(id).appendChild(this.myButton);
StekiUtil.addEventListenerByObject(this.myButton,"click", func );
this.setValue = function(value){
this.myButton.value=value;
};
}
function onMyButtonClick()
{
alert('hi_button_2');
}
function initComponent(){
new MyButton("myButton_1", function (){ alert('hi_button_1'); } );
var myButton2 = new MyButton("myButton_2", onMyButtonClick );
myButton2.setValue("Button click");
StekiUtil.addEventListenerById("myImgButton","click", function(){ alert('hi_img_button'); } );
}
onload=function(){
initComponent();
}
</script>
</HEAD>
<BODY>
<span id="myButton_1"></span>
<br>
<span id="myButton_2"></span>
<br>
<img src="http://sstatic.naver.com/search/images11/btn_gnb_login.gif" id="myImgButton">
</BODY>
</HTML>
<HEAD>
<TITLE> Steki's Dynamic Button Making </TITLE>
<script>
var StekiUtil={
fid:function(id)
{
return document.getElementById(id);
}
, addEventListenerById:function( objId, evtName, fuc )
{
StekiUtil.addEventListenerByObject(StekiUtil.fid(objId), evtName, fuc );
}
, addEventListenerByObject:function( obj, evtName, fuc )
{
if (obj.addEventListener)
{
obj.addEventListener(evtName, fuc, false);
}
else
{
obj.attachEvent("on" + evtName, fuc);
}
if(evtName=="click" && obj){
obj.style.cursor=obj.addEventListener?"pointer":"hand";
}
}
}
function MyButton(id, func ){
this.myButton = document.createElement("input");
this.myButton.name = id;
this.myButton.value = id;
this.myButton.type = "button";
StekiUtil.fid(id).appendChild(this.myButton);
StekiUtil.addEventListenerByObject(this.myButton,"click", func );
this.setValue = function(value){
this.myButton.value=value;
};
}
function onMyButtonClick()
{
alert('hi_button_2');
}
function initComponent(){
new MyButton("myButton_1", function (){ alert('hi_button_1'); } );
var myButton2 = new MyButton("myButton_2", onMyButtonClick );
myButton2.setValue("Button click");
StekiUtil.addEventListenerById("myImgButton","click", function(){ alert('hi_img_button'); } );
}
onload=function(){
initComponent();
}
</script>
</HEAD>
<BODY>
<span id="myButton_1"></span>
<br>
<span id="myButton_2"></span>
<br>
<img src="http://sstatic.naver.com/search/images11/btn_gnb_login.gif" id="myImgButton">
</BODY>
</HTML>