javascript - 使用 javascript spin.js 库时出错

标签 javascript asp.net-mvc

我正在使用 asp mvc,我需要使用 spin.js,但无法正常工作。这是我正在使用的代码。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>spin.js example</title>
    <script src="//cdnjs.cloudflare.com/ajax/libs/spin.js/1.2.7/spin.min.js"></script>
</head>
<body>
    <div id="foo"></div>
    <script>
        var opts = {
            lines: 10, // The number of lines to draw
            length: 7, // The length of each line
            width: 4, // The line thickness
            radius: 10, // The radius of the inner circle
            corners: 1, // Corner roundness (0..1)
            rotate: 0, // The rotation offset
            color: '#000', // #rgb or #rrggbb
            speed: 1, // Rounds per second
            trail: 60, // Afterglow percentage
            shadow: false, // Whether to render a shadow
            hwaccel: false, // Whether to use hardware acceleration
            className: 'spinner', // The CSS class to assign to the spinner
            zIndex: 2e9, // The z-index (defaults to 2000000000)
            top: 25, // Top position relative to parent in px
            left: 25 // Left position relative to parent in px
        };
        var target = document.getElementById('foo');
        var spinner = new Spinner(opts).spin(target);
    </script>
</body>
</html>

但是当我运行它时,这一行显示了一个异常

var spinner = new Spinner(opts).spin(target);

消息是

"Spinner is not defined"

关于如何解决这个问题有什么想法吗?

最佳答案

使用自旋库的完全限定路径,将此处插入 StackOverflow 代码片段时似乎工作正常(字面意思是复制您的问题,没有额外的修改)。这可能表明您的代码存在其他问题(这是整个页面)还是您的浏览器缓存了导致问题的内容。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>spin.js example</title>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/spin.js/1.2.7/spin.min.js"></script>
</head>
<body>
    <div id="foo"></div>
    <script>
        var opts = {
            lines: 10, // The number of lines to draw
            length: 7, // The length of each line
            width: 4, // The line thickness
            radius: 10, // The radius of the inner circle
            corners: 1, // Corner roundness (0..1)
            rotate: 0, // The rotation offset
            color: '#000', // #rgb or #rrggbb
            speed: 1, // Rounds per second
            trail: 60, // Afterglow percentage
            shadow: false, // Whether to render a shadow
            hwaccel: false, // Whether to use hardware acceleration
            className: 'spinner', // The CSS class to assign to the spinner
            zIndex: 2e9, // The z-index (defaults to 2000000000)
            top: 25, // Top position relative to parent in px
            left: 25 // Left position relative to parent in px
        };
        var target = document.getElementById('foo');
        var spinner = new Spinner(opts).spin(target);
    </script>
</body>
</html>

关于javascript - 使用 javascript spin.js 库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26414320/

相关文章:

javascript - Jquery 获取每个 div 的子子 div 并将信息抓取到数组中

javascript - 如何停止免费的jqgrid禁用工具栏按钮来响应鼠标点击

javascript - FullCalendar 事件标题只允许一行

Javascript/jquery 将字符串转换为日期时间(使用 javascript 中的新日期)以传递给 .net MVC

c# - MVC 将 post 参数传递给字典

javascript - 从上午 9 点到下午 12 点,使用触发器每 30 分钟运行一次脚本

javascript - Three.js onClick 动画永远持续下去

asp.net-mvc - ErrorAttribute vs OnException vs Application_Error

jquery - 对象 [object Object] 没有方法 'button' ,使用 Asp.Net MVC4 和 nuget 包中的 JQuery 和 JQuery UI

asp.net-mvc - ASP.NET MVC 模型与 ViewModel