判断当前哪个控件激活:设置一个变量,点击按钮的onclick中将控件的name或者id传递给你按钮的函数

解决方案 »

  1.   

    <html>
    <head>
    </head>
    <html>
    <body>
    <form name=form1 method=post action=sss.jsp>
    <input type=text name=user size=12 onkeypress="document.all.pwd.value=this.value">
    <input type=password name=pwd size=16onkeypress="document.all.user.value=this.value">
    <input type=submit name=submit>
    1 2 3 4 5 6 7 8 9 0 
    clear   backSpace
    </body>
    </html>
      

  2.   

    <head><style>
    .mystyle span{ background-color:#eee;cursor:hand;border:1 solid red;}
    </style>
    </head>
    <body>
    <input type=text name=user size=12 onclick="e=this">
    <input type=password name=pwd size=16 onclick="e=this">
    <input type=submit name=submit>
    <p onclick="add()" class="mystyle">
    <span>1</span> <span>2</span> 
    <span>3</span> <span>4</span> 
    <span>5</span> <span>6</span>
    <span>7</span> <span>8</span> 
    <span>9</span> <span>0</span> </p><p class=mystyle>
    <span onclick="clears()">clear</span>
    <span onclick="backs()">backspace</span> </p>
    <script language="JavaScript">
    <!--
    var e=null;
    function add(){
     if(e && event.srcElement.tagName=="SPAN") e.value+=event.srcElement.innerText; 
    }
    function clears(){
     if(e) e.value = "";
    }
    function backs(){
     if(e) 
     e.value = e.value.substring(0,e.value.length-1); 
    }
    //-->
    </script>
    </body>