我正在尝试制作一个简单的加密站点来进一步摆弄 b64
<html>
<script language="javascript">
function encrypt() {
var texttoencrypt = document.getElementById("text").innerHTML;
var encrypted = btoa(texttoencrypt)
document.getElementById("text").innerHTML = encrypted;
}
</script>
<head></head>
<title>Base64 Encrypt</title>
<body>
<textarea id="text" rows="4" cols="50" autofocus placeholder="Put text here."></textarea>
<br>
<button onclick="encrypt()">Encrypt</button>
<button onclick="decrypt()">Decrypt</button>
</body>
</html>
它给我的错误是:
ReferenceError:未定义加密 在 HTMLButtonElement.onclick
当我点击加密时。
最佳答案
输入您的script
进入头部:
<html>
<head>
<script language="javascript">
function encrypt() {
var texttoencrypt = document.getElementById("text").value;
var encrypted = btoa(texttoencrypt);
document.getElementById("text").value = encrypted + ' - test';
}
function decrypt() {
// ...
}
</script>
</head>
<title>Base64 Encrypt</title>
<body>
<textarea id="text"
rows="4" cols="50"
autofocus placeholder="Put a text here">
</textarea>
<br>
<button onclick="encrypt()">Encrypt</button>
<button onclick="decrypt()">Decrypt</button>
</body>
</html>
更新:您需要使用值属性 document.getElementById("text").value
当您想从 <textarea></textarea>
获取短信时.
关于javascript - 使用 btoa 进行简单加密站点时未声明函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42796372/