jQuery document.ready停止代码

jQuery document.ready stops the code

本文关键字:代码 ready document jQuery      更新时间:2023-09-26

我现在遇到的问题是,当我放置document.ready代码包装脚本时,它停止工作。我知道我不能简单地使用它,因为我只在HTML的末尾调用脚本,但我想知道它为什么会破坏我的代码。附言:我已经添加了jQuery代码:

    $(document).ready(function () {
        $('.clicker').click(function() {
            if($(this).hasClass('clicker'))
            {
                var row_index = $(this).parents('tr').index();
                $(this).text('Cancelar');
                $(this).attr('class', 'cancelar');
                var index = row_index - 2;
                $(".save:eq("+index+")").css('display', 'inline');
            }
            else 
            {
                $(this).text('Editar');
                $(this).attr('class', 'clicker');
                $('.save').css('display', 'none');
            }
        });
    });
//In the end of the html file:
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.2.3.min.js"></script>
<script src="/js/scripts.js"></script>

JQuery应该包含在页面的顶部。

$未定义-您正在尝试运行Jquery,但未定义它,这会破坏您的页面-当您尝试运行document.ready.时,脚本在那里失败