【发布时间】:2017-04-26 00:08:52
【问题描述】:
我正在尝试制作一个简单的程序,用于多次在 base64 中进行编码(并非出于任何特定原因,只是作为示例和实践)。不过,我遇到了很多麻烦,可能是因为我没有喝足够(或可能喝太多)咖啡。
在i 等于times 之前,我似乎无法弄清楚如何将我的变量(文本)重新输入到对其进行编码的函数中
我们将不胜感激!
<html>
<head>
<script>
function encodeThis(text,times) {
var toEncode = text;
for (var i = 0; i < times, i++) {
btoa(toEncode);
}
document.getElementById("result").value = toEncode;
}
</script>
</head>
<body>
<b>Text to Encode</b><br/>
<input type="text" id="encode"><br/>
<b>Number of Times to Encode (Integers Only)<br/>
<input type="text" id="times">
<button type="submit" onclick="encodeThis(encode,times)">Test</button>
<br/>
<br/>
<b>Result</b><br/>
<input type="text" id="result">
</body>
</html>
我是否需要在该函数中放置一个函数来重新输入变量?
【问题讨论】:
-
我觉得应该是
toEncode = btoa(toEncode);
标签: javascript function loops