0

以下是一个 js,当我尝试保存它时,它显示“元素的内容必须由格式良好的字符数据或标记组成。” 错误,请帮我解决这个问题

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<script>
(function(){            

    if ($('html').hasClass('csstransforms3d')) {

        var foldingList = $('.folding'),
            foldingListHeight = $('.folding').height();
            topElemOffset = foldingList.offset().top,
   **===========================================^
    lint warning: multiple statements separated by commas (use semicolons?)**


            // Function responsible for unfolding the list
            unfold = function(){
                setTimeout(function(){
                    if (foldingList.hasClass('folded')){
                        foldingList.removeClass('folded');
                        return;
                    }
                }, 500);
            }

        // Fold/Unfold the list
        $('.connect').on("click",function(){

    **==^
    lint warning: missing semicolon**

            foldingList.toggleClass('folded');
        })
        // If needed, unfold the list right away
        if (topElemOffset <= $(window).height() - foldingListHeight)
            unfold();
    **===^
    lint warning: block statement without curly braces**


        // Check whether to unfold the list when scrolling/resizing
        $(window).on("scroll resize", function(){
            var th = $(this);               
            if (th.scrollTop() + th.height() - foldingListHeight  >=  topElemOffset)
                unfold();
**====^
    lint warning: block statement without curly braces**


        })
    }

})()
</script>
4

1 回答 1

0

错误信息很清楚。

 topElemOffset = foldingList.offset().top; // ; instead of ,

 ...

 $('.connect').on("click",function(){
        foldingList.toggleClass('folded');
    }); // semicolon was mising

 ...
 //write if-statements like this
 if(expression){
     //dowork
 }
于 2013-06-07T11:03:50.010 回答