首先,我知道这个问题之前已经被问过 - 我看过这些答案,但由于某种原因,它根本不适合我!使用Javascript和HTML创建一个清晰的按钮
我有各种各样的,我想有一个“清除”按钮,点击时清空字段的值文本字段。
这是我的JavaScript:
function clear() {
document.getElementById("customerName").value="";
}
和我因为这是HTML ...
<table border="1" id="orderForm">
<tr>
<th colspan="2">Customer Details</th>
</tr>
<tr>
<td id="font">Customer Name</td>
<td><input type="text" id="customerName"></td>
</tr>
</table>
<button type="button" id="button1" onClick="clear()">Clear</button>
我不知道为什么它不会工作,我一直在努力让它工作多年。
试着改变你的函数名。 选中此项[是否清除Javascript中的保留字?](http://stackoverflow.com/questions/7165570/is-clear-a-reserved-word-in-javascript) – Pratyush
这是正确的!简直不敢相信那么简单。非常感谢! –