JS dynamic password input keyboard control source code

Source: Internet
Author: User
Tip: you can modify some code before running

<html><head> <title>Dynamic password input control code demonstration</title><script type="text/javascript" language="javascript">// Define global container IDvar OBJID = "layerDisplay"; // object selector function $ (obj) {return document. getElementById (obj);} // load the function load () {var id = OBJID; // control the internal HTML $ (id ). innerHTML = ""; // reload the library $ (id ). innerHTML = getControl (); // Display $ (id ). style. display = "block" ;}// hide function hide () {var id = OBJID; $ (id ). style. display = "none" ;}// obtain the control function getControl () {var strHtml = ""; // initialize the keyboard strHtml + = initNum (5 ); // OK button strHtml + ="<input type="button" id="btnReload" name="btnReload" value="Rest" class="command" onclick="load()"/>"; // Hide the button strHtml + ="<input type="button" id="btnHide" name="btnHide" value="Hide" class="command" onclick="hide()"/>"; // Set the button and display return strHtml;} function addNum (obj) {var strVal = null; // empty object if (null = obj) {return ;} // empty string or invalid string strVal = obj. value; if ("" = strVal | 0 = strVal. length) {return;} // Append the string $ ("txtDisplay "). value + = strVal // load ()} // initialize the function initNum (line) {var strHtml = ""; var arr = new Array () if (line <1 | line> 10) {return;} // compile a random array while (arr. length <10) {// returns the integer var num between 0-9. = Math. floor (10 * Math. random (); // traverse the array to find the empty var flag = false; for (var I = 0; I <arr. length; I ++) {if (arr [I] = num) {flag = true; break ;}} if (! Flag) {arr [arr. length] = num ;}// list of output buttons for (var I = 9; I >=0; I --) {strHtml + ='<input type="button" class="number" value="' + arr[i] + '" onclick = "addNum(this)" />'; // Control line feed if (0 = (I % line) {strHtml + ='<br />';}} Return strHtml}</script><style type ="text/css">Input {border: 1px solid # CCC; margin: 1px ;}. text {height: 20px; width: 200px; font-size: 28px ;}. number {height: 20px; width: 20px; color: # 00F ;}. command {height: 20px; width: 50px; color: # F00 ;}# layerDisplay {position: absolute; top: 40px; left: 10px; z-index: 1000; border: 1px solid # CCC; background-color: # EEE; display: none ;}</style></head><body><input type="text" id="txtDisplay" name="txtDisplay" onfocus ="load(OBJID)" value="http://www.111cn.net" /><div id="layerDisplay"></div></body></html></td> </tr></table>
Tip: you can modify some code before running

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.