简体   繁体   English

Onclick 方法未定义

[英]Onclick Method is not defined

I have this simple html:我有这个简单的 html:

<head>
  <script src="~/js/Order.js" asp-append-version="true"></script>
</head>
<body>
  <button id="button-1" onclick="ButtonClick(this.id);">This is a button</button>
  ...
</body>

And this is my Order.js file:这是我的 Order.js 文件:

function ButtonClick(buttonID)
{
    alert("Button " + buttonID + " pressed!");
}

But when I click on the button, the console outputs, that ButtonClick is not defined at HTMLButtonElement.onclick .但是,当我单击按钮时,控制台输出, ButtonClick is not defined at HTMLButtonElement.onclick

But this is not true, it definitely is defined in my Order.js file但这不是真的,它肯定是在我的 Order.js 文件中定义的

It seems that there was an error in another function of the script, and so Visual Studio did not distribute my js file.脚本的另一个 function 似乎有错误,因此 Visual Studio 没有分发我的 js 文件。 When I commented the faulty method it worked again当我评论错误的方法时,它再次起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM