JavaScript code for random color input boxes

Source: Internet
Author: User
The Code is as follows:

 Script window. onload = function () {var inps = document. getElementsByTagName ('input'); var btn = document. getElementsByTagName ("button") [0]; // click to obtain table btn. onclick = function () {var table = document. createElement ("table"); var tbody = document. createElement ("tbody"); var n = inps [0]. value; var m = inps [1]. value; for (var I = 1; I <= n; I ++) {var tr = document. createElement ("tr"); // obtain the color value for (var j = 1; j <= m; j ++) {var td = document. createElement ("td"); tr. appendChild (td); var color = "rgb (" + parseInt (Math. random () * 256) + "," + parseInt (Math. random () * 256) + "," + parseInt (Math. random () * 256) + ")"; td. style. backgroundColor = color;} inps [0]. value = ""; inps [1]. value = ""; tbody. appendChild (tr); table. appendChild (tbody); document. body. appendChild (table) ;}} scriptRow:Column:Obtain random color 

The above is the details of the Code for implementing the random color input box in JavaScript. For more information, see other related articles in the first PHP community!

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.