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!