点击开始按钮后浏览器卡死


="random"> ="button" class="ranButton" id="ranButton" onclick="randomName()" value="开始"> ="button" class="ranButton2" id="ranButton2" onclick="randomStop()" style="display:none;" value="停止">
="randomResult" class="ranResult"> aaa
var state=0
function randomName () {
    var x=7,y=8;
    console.log(state);
    document.getElementById("ranButton").style.display="none";
    document.getElementById("ranButton2").style.display="block";
    while (state==0) {
        a();
    }
    function a () {
        while (x>=6) {
            x=Math.floor(Math.random()*10);
            console.log("x:"+x);
        }
        while (y>=7) {
            y=Math.floor(Math.random()*10);
            console.log("y:"+y);
        }
        c="第"+x+"列\n第"+y+"排";
        document.getElementById("randomResult").innerText=c;
    }
}
function randomStop () {
    state=1;
    document.getElementById("ranButton2").style.display="none";
    document.getElementById("ranButton").style.display="block";
    state=0;
}

.ranButton {
    width: 45%;
    height: 15%;
    margin-left: 5%;
    margin-top: 5%;
    border-radius: 45px;
    font-size: 2.5em;
}
.ranButton2 {
    width: 45%;
    height: 15%;
    margin-left: 5%;
    margin-top: 5%;
    border-radius: 45px;
    font-size: 2.5em;
}
.ranResult {
    font-size: 2.8em;
    background-color: rgba(255, 235, 205, 0.778);
    width: 90%;
    margin-left: 5%;
    margin-top: 10%;

}

while (state==0) {
a();
} 死循环
funct如果 生成的随机数都X,Y小于6,7,那你这不是一直循环输入 一样的内容
document.getElementById("randomResult").innerText=c;

img

好家伙 你这不死才怪
while(state==0)永远在执行