为什么我不能从 onclick 属性调用名为 clear 的函数? [英] Why can't I call a function named clear from an onclick attribute?
本文介绍了为什么我不能从 onclick 属性调用名为 clear 的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个简单的计算器,当单击按钮时,其值显示在文本字段中,按钮C"应清除文本字段,但其 onclick="clear()" 不起作用??
<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE html><头><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>计算器</title><风格>#按钮{填充:10px;}</风格><脚本>函数填充(val){document.getElementById("field").value+=val;}函数清除(){document.getElementById("field").value="";}头部><身体><表格><表格><tr><input type="text" name="field" id="field" size="8"/></tr><%!整数 k = 1;%><% for(int i=0;i<3;i++){%><tr><%for(int j=0;j<3;j++){%><td><input type="button" id="button" onclick="fill(this.value)" value="<%=k++%>"/></td><%}%></tr><%}%><tr><!--这里 onclick="clear()" 不起作用??--><td><input type="button" id="button" value="C" onclick="clear()"/></td><td><input type="button" id="button" value="0" onclick="fill(this.value)"</td><td><input type="submit" id="button" value="="</td></tr></表单>