gpt4 book ai didi

javascript - 不能在 QUnit 测试中使用从 http url 引用的 jQuery

转载 作者:行者123 更新时间:2023-11-28 21:29:30 25 4
gpt4 key购买 nike

我尝试像这样在我的 QUnit 测试中包含 jquery:

/// <reference path="http://code.jquery.com/jquery-2.1.3.min.js" />

但是,这一行:

var input = $("<input type='text'/>");

会给我这样的错误:

1.Died on test #1: '$' is undefined

为什么?

最佳答案

我假设您正在 Visual Studio 中进行 .NET 开发?那是我唯一见过 /// <reference ... /> 的地方东西。这实际上并不包括您页面中的源代码,它只是 used for the IntelliSense reference在您的 IDE 中。如果您想在测试中包含 jQuery,那么您需要将它包含在带有 <script> 的 QUnit HTML 文件中。标签就像任何其他引用:

<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>

<!-- and then all of your QUnit stuff... -->
<link rel="stylesheet" href="path/to/qunit.css">
<script src="path/to/qunit.js"></script>
<script src="path/to/your/tests.js"></script>
</head>
<body>
<div id="qunit"></div>
</body>
</html>

关于javascript - 不能在 QUnit 测试中使用从 http url 引用的 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28149892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com