我试图将页面的宽度作为变量传递给 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>
然而,它仍然什么也没做。
- 我已经包含了 JQuery
- 我已经三重检查了我的语法
- 控制台中没有报告任何错误
- 我查看了其他类似的 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 thetype
attribute, but must match script content restrictions.
If there is asrc
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/