任何人看到我的重置功能有错误

Anyone see a mistake with my Reset function?

本文关键字:功能 有错误 我的 任何人      更新时间:2023-09-26

好吧,我制作了一个函数,可以在单击按钮时清除两个文本框。出于某种原因,我不知道它不起作用。代码粘贴在下面-

 function clear() {
            document.getElementById("IMEI").value = "";
            document.getElementById("Command").value = "";
        }
<!-- IMEI -->
        <label><font color=#829DBA face="Tahoma"><b>IMEI:</b></font></label>
        <input type="text" name="ID" id="IMEI" maxlength="15">
        <!-- -->
        <!-- AT Command -->
        <label><font color=#829DBA face="Tahoma"><b>AT Command:</b></font></label>
        <input id="Command" type="text">
        <!-- -->
 
<!-- Clear Button -->
    <button type="button" onclick="clear();">Clear</button>
    <!-- -->

感谢

这是单词clear的作用域问题,将函数名称更改为cleared,您将看到它正常工作。如果由于某种原因无法重命名此函数,也可以使用window.clear()调用该函数。

font标记处有一个错误:color属性需要引号。

 function clear() {
            document.getElementById("IMEI").value = "";
            document.getElementById("Command").value = "";
        }
<!-- IMEI -->
        <label><font color="#829DBA" face="Tahoma"><b>IMEI:</b></font></label>
        <input type="text" name="ID" id="IMEI" maxlength="15">
        <!-- -->
        <!-- AT Command -->
        <label><font color="#829DBA" face="Tahoma"><b>AT Command:</b></font></label>
        <input id="Command" type="text">
        <!-- -->
 
<!-- Clear Button -->
    <button type="button" onclick="clear();">Clear</button>
    <!-- -->