Home >Web Front-end >JS Tutorial >Dynamically add js event implementation code_javascript skills
//Form object
function GetObject(Name)
{
var inputlist=document.all.tags('input');
var i=0;
for(i=0; i
var input=inputlist[i];
if(input.id.indexOf(Name) !=-1)
{
return input ;
}
}
return null;
}
//Set object event
function setEvent(Object,EventName,EventFunction)
{
if(Object = =null)
return;
if(window.addEventListener)
{
//Event codes for other browsers: Mozilla, Netscape, Firefox
//The order of the added events is executed Sequence//Please use addEventListener to add events with on, no need to add on
Object.addEventListener(EventName.replace('on',''), EventFunction, false);
}
else
{
//IE's event code adds the add method to the original event
Object.attachEvent(EventName,EventFunction);
}
}
//Lost focus function
function blur ()
{
var size=lSize.value * 0.3;
pSize.value=ForDight(size,0);
}
//Rounding function
function ForDight(Dight ,How)
{
var Dight = Math.round (Dight*Math.pow(10,How))/Math.pow(10,How);
return Dight;
}
//Execute
var lSize=GetObject('STNumberTextBox1');
var pSize=GetObject('STNumberTextBox2');
setEvent(lSize,'onblur',blur);