未捕获的ReferenceError:< function>没有在HTMLButtonElement.onclick中定义

编程入门 行业动态 更新时间:2024-10-28 02:30:43
本文介绍了未捕获的ReferenceError:< function>没有在HTMLButtonElement.onclick中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 jsfiddle/kgw0x2ng/5/。代码如下:

HTML代码

< div class =loading>正在载入&#8230;< / div> < button type =submitonClick =hideButton()>隐藏< / button> < button type =submitonClick =showButton()>显示< / button>

JS CODE

function hideButton(){ $(。loading)。hide(); } function showButton(){ $(。loading)。show(); }

我正在显示一个微调,并且我希望微调当我点击时隐藏在隐藏按钮上。我收到以下错误:

未捕获的ReferenceError:showButton没有在HTMLButtonElement.onclick(VM282:180)上定义 ) onclick @ VM282:180 VM282:179 Uncaught ReferenceError:hideButton未定义在HTMLButtonElement.onclick(VM282:179) onclick @ VM282:179。

有人可以提出一个解决方案吗?

谢谢 Sachin

解决方案

我也有同样的问题......我将所有脚本写入单独的文件,并通过标记将其添加到body标记后面的HTML文件末尾。 在标签内移动标签后,它可以正常工作。 before:

< / body> < script> require('../ script / viewLog.js')< / script>

after:

<脚本>要求( ../脚本/ viewLog.js')< /脚本> < / body>

I have created my problem on JSFiddle at jsfiddle/kgw0x2ng/5/. The code is as follows

HTML CODE

<div class="loading">Loading&#8230;</div> <button type="submit" onClick="hideButton()">Hide</button> <button type="submit" onClick="showButton()">Show</button>

JS CODE

function hideButton(){ $(".loading").hide(); } function showButton(){ $(".loading").show(); }

I am showing a spinner and I would like the spinner to hide when I click on the "Hide" button. I am getting the following error :

Uncaught ReferenceError: showButton is not defined at HTMLButtonElement.onclick (VM282:180) onclick @ VM282:180 VM282:179 Uncaught ReferenceError: hideButton is not defined at HTMLButtonElement.onclick (VM282:179) onclick @ VM282:179.

Can someone please suggest a solution?

Thanks

Sachin

解决方案

Same Problem I had... I was writing all the script in a seperate file and was adding it through tag into the end of the HTML file after body tag. After moving the the tag inside the body tag it works fine. before :

</body> <script>require('../script/viewLog.js')</script>

after :

<script>require('../script/viewLog.js')</script> </body>

更多推荐

未捕获的ReferenceError:&lt; function&gt;没有在HTMLButtonElement.onclick中定义

本文发布于:2023-11-23 03:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619952.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定义   lt   amp   ReferenceError   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!