0

我想显示一个包含我制作的随机代码的对话框。这是我的功能:

function randomString() {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 8;
    var randomstring = '';
    for (var i = 0; i < string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum, rnum + 1);
    }
    alert(randomstring);
    window.location = "Insert-Transac.jsp";
}

我想显示变量randomstring一段时间并隐藏它。谁能帮我?

4

1 回答 1

0

这行得通吗?

function randomString() {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 8;
    var randomstring = '';
    for (var i = 0; i < string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum, rnum + 1);
    }
    return randomstring;
}
document.getElementById("randstring").innerHTML = randomString();
window.setTimeout(function(){document.getElementById("randstring").innerHTML = ""}, 2000);

这假设您有一个 ID 为 randstring 的元素。

于 2013-04-26T21:32:09.047 回答