gpt4 book ai didi

javascript - 我尝试使用 jscript 从另一个文本区域复制数据后清除文本区域,但无法清除第二个文本区域

转载 作者:行者123 更新时间:2023-11-28 03:54:47 26 4
gpt4 key购买 nike

<!DOCTYPE html>
<html>
<body>

<b>Q1.</b>
<textarea readonly rows="4" columns="200" id="Q1_Old">Answer to be copied to second textarea</textarea>

<p>If the above answer is unchanged click on "Same Answer" for copying over, else click on "New Answer" to draft new answer</p>

<button onclick="SameAnswer()">Same Answer</button>
<input type="button" onclick="clearText()" value="New Answer">

<p><textarea readonly rows="4" columns="200" id="A1"></textarea>

<script>
function clearText() {
document.getElementById("A1").reset();
}

function SameAnswer() {
var x = document.getElementById("Q1_Old").value;
document.getElementById("A1").innerHTML = x;
}
</script>

</body>
</html>

在上面的代码中,SameAnswer() 函数可以正常工作,但 ClearText() 函数不能正常工作。需要帮助来解决此问题

最佳答案

更改.document.getElementById("A1").reset();到 document.getElementById("A1").value = "";

function clearText() {
document.getElementById("A1").value = "";
}

function SameAnswer() {
var x = document.getElementById("Q1_Old").value;
document.getElementById("A1").innerHTML = x;
}
<b>Q1.</b> 
<textarea readonly rows="4" columns="200" id="Q1_Old">Answer to be copied to second textarea</textarea>

<p>If the above answer is unchanged click on "Same Answer" for copying over, else click on "New Answer" to draft new answer</p>

<button onclick="SameAnswer()">Same Answer</button>
<input type="button" onclick="clearText()" value="New Answer">

<p><textarea readonly rows="4" columns="200" id="A1"></textarea>

关于javascript - 我尝试使用 jscript 从另一个文本区域复制数据后清除文本区域,但无法清除第二个文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47641742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com