简体   繁体   English

ASP.NET中的Javascript无法正常工作

[英]Javascript in ASP.NET is not working

I'm back at coding som .NET stuff and I thought I'd play with Javascripts / jQuery. 我回到编码Som .NET的东西,我以为我会使用Javascript / jQuery。
I've added my /js/myscript.js file and it loads when the pages has loaded. 我已经添加了/js/myscript.js文件,并在页面加载后加载。

In my js file I only have one call alert('TEST') . 在我的js文件中,我只有一个通话alert('TEST')

Why isn't the alert triggered? 为什么没有触发警报?

I'm on ASP.NET 4.0 - but I don' think that has anything to do with it. 我使用的是ASP.NET 4.0-但我认为这与它无关。
Is there a way to detect if there is any conflict with other scripts? 有没有一种方法可以检测是否与其他脚本有冲突?

This goes in the header: 这放在标题中:

<script type="text/javascript" src="js/myscript.js" ></script>

After page is loaded, I can use Firebug and exapnd the script and see it's content. 页面加载后,我可以使用Firebug并扩展脚本并查看其内容。 So the script is loaded. 因此脚本已加载。

Embarrassing update 令人尴尬的更新

jQuery(document).ready(function() {
    // Alert if jQuery is loaded
    alert('Test1');
}

alert('Test 2');

As you can see in the above code, I'd forgotten to add the ); 如您在上面的代码中看到的,我忘了添加); and the end of the jQuery(document).ready() function. 以及jQuery(document).ready()函数的末尾。

After a long day, even the simplest things can go unnoticed. 经过漫长的一天,即使是最简单的事情也可能会被忽略。

Always check for Javascript Errors on something like this. 总是检查类似这样的Javascript错误。 All modern browser have built in HTML/Javascript inspectors which you can use to check for these errors. 所有现代浏览器均内置HTML / Javascript检查器,您可以使用它们检查这些错误。

What does your myscript.js look like? 您的myscript.js是什么样的?

function x(){
  alert('TEST');
}

or just (which will execute on load): 或者只是(将在加载时执行):

alert('TEST');

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

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