Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.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
onclick incAtt/decAtt的javascript函数不工作_Javascript_Html - Fatal编程技术网

onclick incAtt/decAtt的javascript函数不工作

onclick incAtt/decAtt的javascript函数不工作,javascript,html,Javascript,Html,所以我是javascript新手,我从互联网上获得了这段代码,它应该通过点击箭头来增加或减少“魔法点”,从“左点”中获取或添加“魔法点”,但它不起作用。我不断得到错误:uncaughtreferenceerror:incAtt未定义 在HTMLButtoneElement.onclick,我知道decAtt函数尚未编写,但我似乎无法让incAtt函数工作,我尝试了document.getElementById(“incAtt”).addEventListener(“单击”,函数(),然后定义id

所以我是javascript新手,我从互联网上获得了这段代码,它应该通过点击箭头来增加或减少“魔法点”,从“左点”中获取或添加“魔法点”,但它不起作用。我不断得到错误:uncaughtreferenceerror:incAtt未定义 在HTMLButtoneElement.onclick,我知道decAtt函数尚未编写,但我似乎无法让incAtt函数工作,我尝试了document.getElementById(“incAtt”).addEventListener(“单击”,函数(),然后定义id=“incAtt”但是这也不起作用。你知道为什么它不起作用吗?它在我复制的网站上工作得非常好

</table>
 <span onclick="incAtt('magic');" style="cursor: pointer;">&#x25B2;</span>
 <span onclick="decAtt('magic');" style="cursor: pointer;">&#x25BC;</span>

            <div id="magic" style="display:inline;">0</div>

          </td>
         </tr>
         <tr>
            <td style="text-align:right;">
              Points left:
            </td>
            <td>
              <div id="points" style="display:inline;">10</div>
            </td>
<table>
           <script function incAtt(att)> {
                pts = parseInt($('#points').html());
                flag = (pts > 0);
                if (flag) {
                  n = parseInt($('#' + att).html());
                  $('#' + att).html(n + 1);
                  $('#points').html(pts - 1);
                }
            }
            </script>

▲;
▼;
0
剩下的几点:
10
{
pts=parseInt($('#points').html();
flag=(pts>0);
国际单项体育联合会(旗){
n=parseInt($('#'+att.html());
$('#'+att).html(n+1);
$(#points').html(pts-1);
}
}

您的
代码似乎有问题。请查看这部分代码
{
这是无效的
语法
,尤其是在javascript内部调用方法时

请尝试此代码。这将解决您的问题


功能incAtt(att){
pts=parseInt($('#points').html();
flag=(pts>0);
国际单项体育联合会(旗){
n=parseInt($('#'+att.html());
$('#'+att).html(n+1);
$(#points').html(pts-1);
}
}

是的,显然语法不正确,我现在注意到,即使使用正确的语法,它也不起作用,我得到一个新错误UncaughtReferenceError:$未在HtmlButtoneElement.onClick的incAtt中定义。如果这是下一个问题,请确保包含“jQuery”在你的主目录上。非常感谢!这解决了我的问题。
<script> 
    function incAtt(att){
           pts = parseInt($('#points').html());
           flag = (pts > 0);
           if (flag) {
               n = parseInt($('#' + att).html());
               $('#' + att).html(n + 1);
               $('#points').html(pts - 1);
           }
    }
</script>