【问题标题】:Can Anyone solve my Javascript Formation Issue?任何人都可以解决我的 Javascript 形成问题吗?
【发布时间】:2013-06-03 09:33:44
【问题描述】:

以下是一个 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>

【问题讨论】:

  • 请添加到 jsfiddle..
  • cmets 不清楚?
  • linting cmets 相当清晰。您想解决这些问题,还是“元素的内容必须由格式正确的字符数据或标记组成”错误,而您没有提到它发生的地点/时间?

标签: javascript syntax-error blogs


【解决方案1】:

错误信息非常清楚。

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

 ...

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

 ...
 //write if-statements like this
 if(expression){
     //dowork
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多