1 var textbox = document.forms[0].elements[0]; 2 3 EventUtil.addHandler(textbox, "focus", function(event) { 4 event = EventUtil.getEvent(event); 5 var target = EventUtil.getTarget(event); 6 7 if (target.style.backgroundColor != "red") { 8 target.style.backgroundColor = "yellow"; 9 } 10 }); 11 12 EventUtil.addHandler(textbox, "blur", function(event) { 13 event = EventUtil.getEvent(event); 14 var target = EventUtil.getTarget(event); 15 16 if (/[^\d]/.test(target.value)) { 17 target.style.backgroundColor = "red"; 18 } else { 19 target.style.backgroundColor = ""; 20 } 21 }); 22 23 EventUtil.addHandler(textbox, "change", function(event) { 24 event = EventUtil.getEvent(event); 25 var target = EventUtil.getTarget(event); 26 27 if (/[^\d]/.test(target.value)) { 28 target.style.backgroundColor = "red"; 29 } else { 30 target.style.backgroundColor = ""; 31 } 32 });
转载于:https://www.cnblogs.com/qzsonline/archive/2012/06/03/2532786.html