textarea应该复制到另一个textarea和原始textarea应该清除在按钮点击使用javascript [英] textarea should get copy to another textarea and original textarea should be cleared on a button click using javascript
问题描述
我有以下代码。
它显示两个 textarea
s,其中 textarea
使用JavaScript
< head> ;< script type =text / javascript> function displayOut(){var input = document.getElementById(txt)。value; var text2 = document.getElementById(txt1); text2.value = input; if(input.length === 0){alert(Please enter a valid input); return;} function eraseText(){document.getElementById(txt)。value =;}}< / script>< / head>
< body>< h1 id =result> Javascript Exm< / h1>< textarea id =txt1 rows =10cols =100readonly =readonly>< / textarea>< textarea id =txtrows =4cols =50onclick =eraseText()> ; / textarea>< input type =buttononclick =displayOut()value =click>< / body>
/ div>
我要完成以下操作:
1)点击按钮,到另一个 textarea
和从 textarea
ie的文本。第一个 textarea
应该清楚接受其他文本,所以我有一个擦除功能,但它不工作。
2)我想要显示的文本应该在第二个 textarea
中以连续的格式复制到一个按钮上。
尝试这个。你似乎已经声明EraseText作为一个函数,但实际上并没有调用它。添加\ n在text2中给出换行符。
function displayOut(){var input = document.getElementById(txt )。值; if(input.length === 0){alert(Please enter a valid input);返回; } var text2 = document.getElementById(txt1); text2.value + = input +\\\
; eraseText(); } function eraseText(){document.getElementById(txt)。value =; }
< textarea id =txt1rows = 10cols =100readonly =readonly>< / textarea>< textarea id =txtrows =4cols =50onclick =eraseText()>< / textarea> ;< input type =buttononclick =displayOut()value =click>
I have the following code.
It displays two textarea
s where the text from one textarea
gets copied to another textarea
on a button click using JavaScript
<head>
<script type="text/javascript">
function displayOut(){
var input=document.getElementById("txt").value;
var text2=document.getElementById("txt1");
text2.value=input;
if(input.length===0)
{
alert("Please enter a valid input");
return;
}
function eraseText() {
document.getElementById("txt").value = "";
}
}
</script>
</head>
<body>
<h1 id="result">Javascript Exm</h1>
<textarea id="txt1" rows="10" cols="100" readonly="readonly" ></textarea>
<textarea id="txt" rows="4" cols="50" onclick="eraseText()"></textarea><input type="button" onclick="displayOut()" value="click">
</body>
I want to accomplish the following:
1)On button click the text should get copied to another textarea
and the text from origial textarea
ie. first textarea
should get clear to accept other text, so i have an erase function but it doesn't work.
2) I want to display the text should get copied in second textarea
in a continuous format one below the other on a button click.
Try this. You seemed to have declared EraseText as a function but not actually called it. Adding the "\n" gives the line breaks in text2.
function displayOut(){
var input=document.getElementById("txt").value;
if(input.length===0)
{
alert("Please enter a valid input");
return;
}
var text2=document.getElementById("txt1");
text2.value += input+"\n";
eraseText();
}
function eraseText() {
document.getElementById("txt").value = "";
}
<textarea id="txt1" rows="10" cols="100" readonly="readonly" ></textarea>
<textarea id="txt" rows="4" cols="50" onclick="eraseText()"></textarea><input type="button" onclick="displayOut()" value="click">
这篇关于textarea应该复制到另一个textarea和原始textarea应该清除在按钮点击使用javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!