随机选取一个人

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<textarea id="allCount" rows="3" cols="100">
湖南印象,六扇门,小郡肝,西餐
</textarea>
<button id="btn1" onclick="test()">选哪个呢</button>
<script>
    function test(){
            // var string = "湖南印象,六扇门,小郡肝,西餐";
            // var array = string.split(",");
            // var value = array[Math.round(Math.random()*(array.length-1))];
            // alert(value);
        var allText = document.getElementById("allCount").value;
        console.log('allText', allText);
        var array = allText.split(",");
        console.log('array',array);
        var value = array[Math.round(Math.random()*(array.length-1))];
        alert(value);
    }
</script>
</body>
</html>

 

posted on 2019-09-10 19:03  Lauren_J  阅读(273)  评论(0编辑  收藏  举报

导航