zoukankan      html  css  js  c++  java
  • input输入框(blur,change,focus)

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml">
     3 <head>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
     5     <title>input输入框(blur,change,focus)</title>
     6     <script type="text/javascript" src="eventutil.js"></script>
     7 </head>
     8 <body>
     9     <form action="#" method="post">
    10         <input type="text" />
    11     </form>
    12     <script type="text/javascript" src="test02.js"></script>
    13 </body>
    14 </html>
     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 });
  • 相关阅读:
    面试知识点连接汇总:
    spring学习二:jdbc相关回顾以及spring下dao
    spring学习一:spring入门及相关概念介绍
    日常暖手
    日常暖手
    从破解实例到探讨反调试
    一个有趣的CM
    复健小CM
    Windows下利用py2exe生成静默运行的命令行程序
    获取指定窗口内的文本
  • 原文地址:https://www.cnblogs.com/qzsonline/p/2532786.html
Copyright © 2011-2022 走看看