![](/img/trans.png)
[英]how to insert value of an textarea to another textarea with javascript
[英]How to get a textarea's value and put it into another textarea using Javascript?
我正在尝试使用Javascript开发一个url解码器但是我的代码不起作用,有人能告诉我怎么做,thx
<textarea id="input"></textarea>
<br />
<button id="yes" align="center" onclick="getInput(document.getElementById('input')">Click to transfer</button>
<p>The decoded URL:</p>
<textarea id="decode"></textarea>
<script>
function getInput(inputElement) {
var decoded = "";
if inputElement == 0 {
document.write("You didn't input anything");
} else if {
var uri = inputElement;
var uri_decode = decodeURIComponent(uri);
var uri_encode = encodeURIComponent(uri)
document.getElementById("decode").innerHTML = uri_decode;
document.getElementById("encode").innerHTML = uri_encode;
decoded = uri_decode;
}
return decoded;
}
</script>
假设逻辑在原始代码中正确完成。
由于它是文本区域,因此必须使用value
试试:
document.getElementById("decode").value = uri_decode;
更多房产在这里
即使即时通讯还是很新的,我想我发现了一些错误,我不确定它是否会解决你的问题,但是你应该试一试。
1. <script>
需要是:
<script type="text/javascript">
否则你的浏览器不知道它需要什么类型的脚本。
2. if inputElement == 0 {
需要:“ if (inputElement == 0) {
3. } else if {
应该是} else {
关闭脚本保持不变: </script>
我希望这有效,如果没有,那么告诉我。
在你的else中 ,你没有指定if语句。 你猜其他意思
我的建议是使用jQuery Api。
单击按钮后,您可以使用它来进行拾取
$('#transfer').click(function() { }
然后只需使用第一个文本框收集文本
var url = $('#urlToDecode').val();
然后使用“将'url'变量写入第二个文本框
$("#decodedURL").val = url;
希望有所帮助! :)注意:您需要链接到由Google托管的jQuery API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.