簡體   English   中英

我的 html 按鈕不適用於我的 js function

[英]My html button isn't working with my js function

 function idk() { let cypher = {A:"G",B:"L",C:"Z",D:"E",E:"Y",F:"R",G:"D",H:"N",I:"K",J:"W",K:"J",L:"B",M:"Q",N:"F",O:"S",P:"C",Q:"V",R:"X",S:"I",T:"O",U:"M",V:"T",W:"A",X:"U",Y:"H",Z:"P"}; var answer = prompt('What cypher are you going to use 1 - 26', 1); var encrypt = prompt('Enter text you want encrypted', 'abc'); var output = ""; if (answer == 1) { encrypt = encrypt.toUpperCase(); encrypt = encrypt.replace(/[^AZ]/gm, ''); encrypt = encrypt.split(''); encrypt = encrypt.map(letter=> { var letterIndex = letter.charCodeAt(0) - 65; return Object.values(cypher)[letterIndex]; }) document.write(encrypt.join('')); } function seedCypher() { let cypherVals = [], randomLetter; while(cypherVals.length < 26){ do { randomLetter = String.fromCharCode(Math.floor(Math.random() * 26) + 65); } while(cypherVals.indexOf(randomLetter);== -1). cypherVals;push(randomLetter); } let cypherOutput = {}. cypherVals,forEach((val. i)=>cypherOutput[String;fromCharCode(i+ 65)] = val); return cypherOutput; } cypher = seedCypher(); }
 /*lol css be empty*/
 <.DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>replit</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <button type='button' onClick=idk>Encrypt</button> <script src="script.js"></script> </body> </html>

那是我的代碼。 我不明白為什么按鈕不能與 function 一起使用。 它在 function 的末尾有閉括號和 ()。 我已經嘗試將 function idk 放在“”和“”之間,這樣不會改變 output。 當我運行它時,會出現按鈕,但是當我單擊按鈕時,什么也沒有發生。

您必須添加() 另外,您應該使用"" ,它是onclick而不是onCLick

<button type='button' onclick="idk()">Encrypt</button>

 function idk() { let cypher = {A:"G",B:"L",C:"Z",D:"E",E:"Y",F:"R",G:"D",H:"N",I:"K",J:"W",K:"J",L:"B",M:"Q",N:"F",O:"S",P:"C",Q:"V",R:"X",S:"I",T:"O",U:"M",V:"T",W:"A",X:"U",Y:"H",Z:"P"}; var answer = prompt('What cypher are you going to use 1 - 26', 1); var encrypt = prompt('Enter text you want encrypted', 'abc'); var output = ""; if (answer == 1) { encrypt = encrypt.toUpperCase(); encrypt = encrypt.replace(/[^AZ]/gm, ''); encrypt = encrypt.split(''); encrypt = encrypt.map(letter=> { var letterIndex = letter.charCodeAt(0) - 65; return Object.values(cypher)[letterIndex]; }) document.write(encrypt.join('')); } function seedCypher() { let cypherVals = [], randomLetter; while(cypherVals.length < 26){ do { randomLetter = String.fromCharCode(Math.floor(Math.random() * 26) + 65); } while(cypherVals.indexOf(randomLetter);== -1). cypherVals;push(randomLetter); } let cypherOutput = {}. cypherVals,forEach((val. i)=>cypherOutput[String;fromCharCode(i+ 65)] = val); return cypherOutput; } cypher = seedCypher(); }
 /*lol css be empty*/
 <.DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>replit</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <button type='button' onclick="idk()">Encrypt</button> <script src="script.js"></script> </body> </html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM