亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

文本區域中的隨機數生成器

文本區域中的隨機數生成器

aluckdog 2023-07-20 17:08:35
如何添加以下 JavaScript 代碼(隨機數生成器)?function randomNumber(max) {    return Math.floor(Math.random() * max + 1);}const list = []while(list.length < 25) {    let nbr = randomNumber(25)    if(!list.find(el => el === nbr))         list.push(nbr)}console.log("list",list)進入這個文本區域并用 DOM 顯示它們?<!DOCTYPE html><html><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>Document</title></head><body>    <textarea name="" id="" cols="30" rows="10"></textarea>    <script src="app.js"></script></body></html>
查看完整描述

1 回答

?
largeQ

TA貢獻2039條經驗 獲得超8個贊

// Using an id to get the element

const textarea = document.getElementById('area');


function randomNumber(max) {

    return Math.floor(Math.random() * max + 1);

}


const list = []

while(list.length < 25 ){

    let nbr = randomNumber(25)

    if(!list.find(el => el === nbr)) 

        list.push(nbr)

}


// Set the value to the list

textarea.value = list;

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>

<body>

    <textarea name="" id="area" cols="30" rows="10"></textarea>

    <script src="app.js"></script>

</body>

</html>


查看完整回答
反對 回復 2023-07-20
  • 1 回答
  • 0 關注
  • 220 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號