Friday, December 28, 2012

onfocus

Event handler onfocus (Bubbles: No, Cancelable: No) terjadi ketika suatu elemen mendapatkan fokus -- menjadi aktif.

Berikut contoh meregister event handler onfocus via 'inline model':

<FORM> Tulis nama Anda: <INPUT TYPE="text" ONFOCUS="this.style.background='red'"> </FORM>

Berikut contoh meregister event handler onfocus via 'traditional model':

<FORM> Tulis nama Anda: <INPUT TYPE="text" ID="inputTextID"> </FORM> <SCRIPT TYPE="text/javascript"> function HandleEvent() { this.style.background="red"; } var inputElem=document.getElementById("inputTextID"); inputElem.onfocus=HandleEvent; </SCRIPT>

Berikut contoh meregister event handler onfocus via DOM:

<FORM> Tulis nama Anda: <INPUT TYPE="text" ID="inputTextID"> </FORM> <SCRIPT TYPE="text/javascript"> function HandleEvent() { this.style.background="red"; } var inputElem=document.getElementById("inputTextID"); inputElem.addEventListener("focus", HandleEvent, false); </SCRIPT>