如何使用javascript使用html中的按钮清除文本区域? [英] How to clear text area with a button in html using javascript?
本文介绍了如何使用javascript使用html中的按钮清除文本区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 html 中有按钮
I have button in html
<input type="button" value="Clear">
<textarea id='output' rows=20 cols=90></textarea>
如果我有一个外部 javascript (.js) 函数,我应该写什么?
If I have an external javascript (.js) function, what should I write?
推荐答案
在你的html中添加按钮点击功能
Change in your html with adding the function on the button click
<input type="button" value="Clear" onclick="javascript:eraseText();">
<textarea id='output' rows=20 cols=90></textarea>
在你的 js 文件中试试这个:
Try this in your js file:
function eraseText() {
document.getElementById("output").value = "";
}
这篇关于如何使用javascript使用html中的按钮清除文本区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文