c# - 为什么这个非常简单的 JQuery 不起作用?

标签 c# javascript jquery asp.net

我试图将页面的宽度作为变量传递给 asp.net 后面的 C# 代码,但只收到空字符串。我将范围缩小到 JQuery 函数根本没有触发的问题。我将其更改为最简单的代码,我可以只是测试该函数是否正在执行任何操作:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
    $(document).ready(function() 
    {
           alert("hello");
    });
</script>

然而,它仍然什么也没做。

  1. 我已经包含了 JQuery
  2. 我已经三重检查了我的语法
  3. 控制台中没有报告任何错误
  4. 我查看了其他类似的 SO 'facepalm' 问题,但他们的解决方案都不起作用(见上文)

我错过了什么非常明显的事情?

最佳答案

您不能同时设置 [src]属性并包含 <script> 的内容元素。

如果需要两个脚本,则需要使用两个单独的<script>元素。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
    jQuery(function($) {
        alert("hello");
    });
</script>

根据 HTML5 spec on the <script> element :

If there is no src attribute, depends on the value of the type attribute, but must match script content restrictions.
If there is a src attribute, the element must be either empty or contain only script documentation that also matches script content restrictions.

关于c# - 为什么这个非常简单的 JQuery 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21488145/

相关文章:

javascript - PHP 变量值传递给 DatePicker Javascript

javascript - 如何使用图表数据更改 D3 Dimple 工具提示?

php - 我无法将值传递给 uploadify scriptData

c# - 如何使用扩展构建双重调度

c# - 显示数据库中的分层数据?

javascript - 如何通过 JavaScript 显示图像

jquery - 如何更改选定元素的多个实例的位置

javascript - 如何让div出现在用户点击的位置?

c# - 如何更改 ILoggerFacade 实现以使用 CallerMemberName 属性跟踪调用方方法?

c# - 在 C# 中重启 Windows 服务