如何清除文本区域中使用JavaScript的HTML按钮?
问题描述:
我在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 = "";
}