我正在尝试为示例项目制作一个快速的base64转换器,并且我成功地将文本输出为警报,但在替换textarea中的文本时却没有。奇怪的是,我能够让它工作一次,但是一旦我刷新页面再次尝试它就停止了工作。我试过JSFiddle,但它没有在我的JavSCript代码中显示任何错误,但它可能是其他问题?代码如下。
<h3>Decoders and Encoders</h3>
Base64 Decoder/Encoder<br>
<textarea name="base64-textarea" cols="50" rows="20" id="basesixfour"></textarea><br>
<input type="submit" value="Decode" id="inline left" onclick="base64-decode()">
<input type="submit" value="Encode" id="inline left" onclick="base64-encode()">
<script language="javascript">
function base64-decode() {
var getText = document.getElementById('basesixfour').value;
var base64-decode = atob(getText);
document.getElementById('basesixfour').value = base64-decode;
}
function base64-encode() {
var getText = document.getElementById('basesixfour').value;
var base64-encode = btoa(getText);
document.getElementById('basesixfour').value = base64-encode;
}
</script>
答案 0 :(得分:1)
你有错字 改变:
base64-encode -> base64_encode
和
base64-decode -> base64_decode
<h3>Decoders and Encoders</h3>
Base64 Decoder/Encoder<br>
<textarea name="base64-textarea" cols="50" rows="20" id="basesixfour"></textarea><br>
<input type="submit" value="Decode" id="inline left" onclick="base64_decode()">
<input type="submit" value="Encode" id="inline left" onclick="base64_encode()">
<script language="javascript">
function base64_decode() {
var getText = document.getElementById('basesixfour').value;
var base64_decode = atob(getText);
document.getElementById('basesixfour').value = base64_decode;
}
function base64_encode() {
var getText = document.getElementById('basesixfour').value;
var base64_encode = btoa(getText);
document.getElementById('basesixfour').value = base64_encode;
}
</script>