触发onclick事件js报错 Uncaught TypeError: addVouchers is not a function at HTMLButtonElement.解决方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_35960326/article/details/82719067

    HTML代码
                     <tr>
                        <td colspan="6" style="width:70%;" class="modity">担保信息&nbsp;&nbsp;</td>
                        <td colspan="2"style="width:30%;" class="modity cushion">
                            <button type="button" id="addVouchers" onclick="addVouchers()" style="width:100px;">添加担保信息</button>
                        </td>
                     </tr>

点击【添加担保信息】按钮,页面无反应,F12,发现JS报错。

报错信息如下:

Uncaught TypeError: addVouchers is not a function at HTMLButtonElement.onclick

报错原因:button按钮绑定的onclick事件中的函数名与 button标签中的 id 或者 name 重复。

解决方法:改掉onclick触发的函数名或者改掉button标签的id 或者name 均可。

猜你喜欢

转载自blog.csdn.net/sinat_35960326/article/details/82719067