javascript random_elem_code

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript random_elem_code相关的知识,希望对你有一定的参考价值。


    
        var custom_elems = ['span','div','p','ul','li'];
        var rand = custom_elems[Math.floor(Math.random()*custom_elems.length)];

        var para = document.createElement(rand);
        para.style.display = "none";
        var str = randomString(12);
        
        para.classList.add(randomString(12));
        var node = document.createTextNode(randomString(88));
para.appendChild(node);
        var element = document.getElementById("app");
        element.appendChild(para);




    function randomString(length) {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        for(var i = 0; i < length; i++) {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
        }
        return text;
    }

以上是关于javascript random_elem_code的主要内容,如果未能解决你的问题,请参考以下文章

javascript JavaScript isset()等效: - JavaScript

JavaScript 使用JavaScript更改CSS(JavaScript)

JavaScript之基础-1 JavaScript(概述基础语法)

前端基础-JavaScript的基本概述和语法

JavaScript

JavaScript