Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于清除表单文本输入字段的javascript函数不起作用_Javascript_Html_Function_Web - Fatal编程技术网

用于清除表单文本输入字段的javascript函数不起作用

用于清除表单文本输入字段的javascript函数不起作用,javascript,html,function,web,Javascript,Html,Function,Web,尽管还有很多工作要做,但是基本的计算器已经完成了,除了clear函数外,其他一切都很好。我无法让它清除查看器。需要立即帮助 (我将所有内容都放在一个文件中,以便每个人都能轻松理解全部内容) 请避免使用这种款式 所以基本上我制作了这个非常简单的计算器,它的函数是clear() 关于如何实现此功能以清除查看器,您有什么想法吗 <!DOCTYPE html> <html> <head> <script> function insert(num

尽管还有很多工作要做,但是基本的计算器已经完成了,除了clear函数外,其他一切都很好。我无法让它清除查看器。需要立即帮助

(我将所有内容都放在一个文件中,以便每个人都能轻松理解全部内容)

请避免使用这种款式

所以基本上我制作了这个非常简单的计算器,它的函数是clear() 关于如何实现此功能以清除查看器,您有什么想法吗

<!DOCTYPE html>
<html>


<head>


<script>
  function insert(num) {
    document.view.viewer.value = document.view.viewer.value+num
  }
  function equal() {
    document.view.viewer.value = eval(document.view.viewer.value);
  }
  function clear() {
    document.view.viewer.value = "";
  }
</script>


<style>
body {
  background-image: url("peepee.png"); 
}
*{
  margin: 0px;
  padding: 0px;
}
.button {
  height:100px;
  width:100px;
  background-color:grey;
  text-align:center;
  margin:2px;
  font-size: 50px;
  cursor: pointer;
  border: 0px;
}
.clear {
  height:100px;
  width:400px;
  background-color: red;
  text-align:center;
  margin:2px;
  font-size: 50px;
  cursor: pointer;
  border: 0px;  
}
.viewer {
  height: 100px;
  width: 430px;
  font-size: 50px;
  margin: 2px
}
</style>


</head>


<body>
  <div class= "main">
    <form name= "view">
      <input class="viewer" name= "viewer">
    </form>
    <table>
      <tr>
        <td><input class="button" value="7" onclick= "insert(7)"></td>
        <td><input class="button" value="8" onclick= "insert(8)"></td>
        <td><input class="button" value="9" onclick= "insert(9)"></td>
        <td><input class="button" value="-" onclick= "insert('/')"></td>
      </tr>
      <tr>
        <td><input class="button" value="4" onclick= "insert(4)"></td>
        <td><input class="button" value="5" onclick= "insert(5)"></td>
        <td><input class="button" value="6" onclick= "insert(6)"></td>
        <td><input class="button" value="x" onclick= "insert('*')"></td>
      </tr>
      <tr>
        <td><input class="button" value="1" onclick= "insert(1)"></td>
        <td><input class="button" value="2" onclick= "insert(2)"></td>
        <td><input class="button" value="3" onclick= "insert(3)"></td>
        <td><input class="button" value="-" onclick= "insert('-')"></td>
      </tr>
      <tr>
        <td><input class="button" value="0" onclick= "insert(0)"></td>
        <td><input class="button" value="." onclick= "insert('.')"></td>
        <td><input class="button" value="=" onclick= "equal()"></td>
        <td><input class="button" value="+" onclick= "insert('+')"></td>
      </tr>
    </table>
    <table>
      <tr>
        <td><input class= "clear" value="Clear" onclick= "clear()"></td>
      </tr>
    </table>
  </div>
</body>


</html>

函数插入(num){
document.view.viewer.value=document.view.viewer.value+num
}
函数相等(){
document.view.viewer.value=eval(document.view.viewer.value);
}
函数clear(){
document.view.viewer.value=“”;
}
身体{
背景图片:url(“peepee.png”);
}
*{
边际:0px;
填充:0px;
}
.按钮{
高度:100px;
宽度:100px;
背景颜色:灰色;
文本对齐:居中;
保证金:2倍;
字体大小:50px;
光标:指针;
边界:0px;
}
.清楚{
高度:100px;
宽度:400px;
背景色:红色;
文本对齐:居中;
保证金:2倍;
字体大小:50px;
光标:指针;
边界:0px;
}
.观众{
高度:100px;
宽度:430px;
字体大小:50px;
利润:2倍
}
所以我想出了一个解决方案,你没有给出你的
输入类型
并将
clear
函数更改为其他
clearText
。信息技术 似乎
clear
函数是某种内置函数 并将
defer
属性放入脚本标记中,以便在
正文之后加载

函数明文(){
log(“单击清除按钮!”);
document.view.viewer.value=“”;
};

所以我想出了一个解决方案,你没有给出你的
输入类型
并将
clear
函数更改为其他
clearText
。信息技术 似乎
clear
函数是某种内置函数 并将
defer
属性放入脚本标记中,以便在
正文之后加载

函数明文(){
log(“单击清除按钮!”);
document.view.viewer.value=“”;
};

函数插入(num){
document.view.viewer.value=document.view.viewer.value+num
}
函数相等(){
document.view.viewer.value=eval(document.view.viewer.value);
}
函数clearInput(){
document.view.viewer.value=“”;
}
正文{
背景图片:url(“peepee.png”);
}
*{
边际:0px;
填充:0px;
}
.按钮{
高度:100px;
宽度:100px;
背景颜色:灰色;
文本对齐:居中;
保证金:2倍;
字体大小:50px;
光标:指针;
边界:0px;
}
.清楚{
高度:100px;
宽度:400px;
背景色:红色;
文本对齐:居中;
保证金:2倍;
字体大小:50px;
光标:指针;
边界:0px;
}
.观众{
高度:100px;
宽度:430px;
字体大小:50px;
利润:2倍
}

函数插入(num){
document.view.viewer.value=document.view.viewer.value+num
}
函数相等(){
document.view.viewer.value=eval(document.view.viewer.value);
}
函数clearInput(){
document.view.viewer.value=“”;
}
正文{
背景图片:url(“peepee.png”);
}
*{
边际:0px;
填充:0px;
}
.按钮{
高度:100px;
宽度:100px;
背景颜色:灰色;
文本对齐:居中;
保证金:2倍;
字体大小:50px;
光标:指针;
边界:0px;
}
.清楚{
高度:100px;
宽度:400px;
背景色:红色;
文本对齐:居中;
保证金:2倍;
字体大小:50px;
光标:指针;
边界:0px;
}
.观众{
高度:100px;
宽度:430px;
字体大小:50px;
利润:2倍
}

我同意萨詹·卡恩的观点。JavaScript
clear
函数是清除JavaScript控制台的默认函数

在这种情况下,只需将函数重命名为
clearView
,例如:

<script>
  function insert(num) {
    document.view.viewer.value = document.view.viewer.value+num
  }
  function equal() {
    document.view.viewer.value = eval(document.view.viewer.value);
  }
  function clearView() {
    document.view.viewer.value = "";
  }
</script>

我希望这能回答你的问题,祝计算器好运

我同意萨詹·卡恩的观点。JavaScript
clear
函数是清除JavaScript控制台的默认函数

在这种情况下,只需将函数重命名为
clearView
,例如:

<script>
  function insert(num) {
    document.view.viewer.value = document.view.viewer.value+num
  }
  function equal() {
    document.view.viewer.value = eval(document.view.viewer.value);
  }
  function clearView() {
    document.view.viewer.value = "";
  }
</script>

我希望这能回答你的问题,祝计算器好运

同时回答。这是函数调用中的实际问题。向上投票。同一时间回答。这是函数调用中的实际问题。投票表决。
<script>
    document.querySelector('input.clear').addEventListener('click', function() {
        document.view.viewer.value = '';
    });
</script>