好的,你能在这里发现语法错误吗?

时间:2010-11-25 10:09:52

标签: javascript jquery

Eclipse在这些方面给我一个语法错误,但我没有看到任何错误:

$('.addNewFolder').click(function() {
    showModal('modal_div', 'Nový adresár');
    var id = '<?php echo ToHtml($idFolder); ?>';
    $('.folders .trow1').each(function() {
        if ($(this).css('backgroundColor') == 'rgb(52, 108, 182)' || $(this).css('backgroundColor') == '#346cb6') {
            id = $(this).attr('rel');
        }
    });
    ajaxElementCall('modal_div', 'body/obsah/obrazy/folderAdd.php?idFolder='+id);
});

PHP解析后:

$('.addNewFolder').click(function() {
    showModal('modal_div', 'Nový adresár');
    var id = '';
    $('.folders .trow1').each(function() {
        if ($(this).css('backgroundColor') == 'rgb(52, 108, 182)' || $(this).css('backgroundColor') == '#346cb6') {
            id = $(this).attr('rel');
        }
    });
    ajaxElementCall('modal_div', 'body/obsah/obrazy/folderAdd.php?idFolder='+id);
});

这就是IDE所说的:

Syntax error on token "}", invalid MethodHeaderName

我一直盯着那段代码至少半个小时。无论是盲人还是疯了。

编辑:

页面上的整个javascript:

<script type="text/javascript">
    //<!--
$(document).ready(function() {

    function in_array (needle, haystack, argStrict) {
        var key = '', strict = !!argStrict; 
        if (strict) {
            for (key in haystack) {
                if (haystack[key] === needle) {
                    return true;            }
            }
        } else {
            for (key in haystack) {
                if (haystack[key] == needle) {
                    return true;
                }
            }
        }
         return false;
    }

    var openedFolders = new Array();
    <?php if (count($_SESSION['ECM']['openedSlideFolders']) > 0) : ?>
    <?php $i = 0; foreach ($_SESSION['ECM']['openedSlideFolders'] as $aVal): ?>
        <?php echo "openedFolders[$i] = '$aVal';\n"; ?>
    <?php ++$i; endforeach; ?>
    <?php endif; ?>

    var start = 0;
    var stop = 0;
    $('.drag').each(function() {
        var draggables = $(this).parents('table').find('.drag');
        var $next = draggables.filter(':gt(' + draggables.index(this) + ')').first();
        var width = $(this).css('width');
        var nextWidth = $next.css('width');
        if (nextWidth > width && 30 == parseInt(width)) {
            $(this).removeClass('ordinaryFolderClosed');
            $(this).removeClass('ordinaryFolderOpened');
            if (in_array($(this).attr('rel'), openedFolders)) {
                $(this).addClass('ordinaryFolderOpened');
            } else {
                $(this).addClass('ordinaryFolderClosed');
            }               
        }
        if (in_array($(this).attr('rel'), openedFolders)) {
            start = 1;
        }
        if (1 == start && stop < 2) {               
            if (30 == parseInt(width)) {
                stop++;
            }
        } else {
            start = 0;
            stop = 0;
            if (parseInt(width) > 30) {
                $(this).parent().parent().hide();
            }
        }
    });

    function dragDrop()
    {
        $('.folders .trow1').hover(
            function () {
                if ($(this).css('backgroundColor') != 'rgb(52, 108, 182)' && $(this).css('backgroundColor') != '#346cb6') {
                    $(this).css('background', "#C2E3EF");
                }
            },
            function () {
                if ($(this).css('backgroundColor') != 'rgb(52, 108, 182)' && $(this).css('backgroundColor') != '#346cb6') {
                    $(this).css('background', 'transparent');   
                }
            }
        );

        $('.drag').click(function() {
            var draggables = $(this).parents('table').find('.drag');
            var $next = draggables.filter(':gt(' + draggables.index(this) + ')').first();
            var width = $(this).css('width');
            var nextWidth = $next.css('width');
            if (nextWidth > width && 30 == parseInt(width)) {
                var isVisible = $next.is(':visible');
                if (isVisible) {
                    $(this).removeClass('ordinaryFolderClosed');
                    $(this).removeClass('ordinaryFolderOpened');
                    $(this).addClass('ordinaryFolderClosed');
                } else {
                    $(this).removeClass('ordinaryFolderClosed');
                    $(this).removeClass('ordinaryFolderOpened');
                    $(this).addClass('ordinaryFolderOpened');
                }
                clickedId = $(this).attr('rel');
                $.ajax({
                    type:    'POST',
                    url:     'body/obsah/obrazy/setOpenedFolder.php',
                    data:    'id='+clickedId,
                    success: function(msg){
                        //alert(msg);
                    }
                });
                var start = 0;
                var stop = 0;
                var i = 0;
                $('.drag').each(function() {
                    if (0 == start) {
                        iteratedId = $(this).attr('rel');
                        if (iteratedId == clickedId) {
                            start = 1;
                        }
                    }
                    if (1 == start && stop < 2) {
                        if ($(this).css('width') > width) {
                            if (isVisible) {
                                $(this).parent().parent().hide();
                            } else {
                                $(this).parent().parent().show();
                            }                           
                        } else {
                            stop++;
                        }
                    }
                    i++;
                });
            }
        }); 

        var dragId = 0;
        var dropId = 0;
        var isFile = false;

        $('.drag').mousedown(function() {
            if ($(this).attr('rel') !== undefined) {
                dragId = $(this).attr('rel');
                dragId = dragId.split(',');
                dragId = dragId[0];
            }
            isFile = false;
        });

        $('.drag2').mousedown(function() {
            if ($(this).attr('rel') !== undefined) {
                dragId = $(this).attr('rel');
                dragId = dragId.split(',');
                dragId = dragId[0];
            }
            isFile = true;
        }); 

        $('.drag').draggable({ 
            revert: true,
            cursorAt: {top: 0, left: 0}
        });

        $('.drag2').draggable({
            revert: true,
            cursorAt: {top: 0, left: 0}
        });


        $('.drop').droppable({
            tolerance: 'pointer',
            drop: function() {
                if ($(this).attr('rel') !== undefined) {
                    dropId = $(this).attr('rel');
                    dropId = dropId.split(',');
                    dropId = dropId[0];
                    if (dropId != dragId) {
                        if (false == isFile) {
                            $.ajax({
                                type:    'POST',
                                url:     'body/obsah/obrazy/folderMove.php',
                                data:    'nid='+dragId+'&pid='+dropId,
                                success: function(msg){
                                    <?php echo $aJsOnDrop; ?>;
                                    dragDrop();
                                }
                            });
                        } else if (true == isFile) {
                            $.ajax({
                                type:    'POST',
                                url:     'body/obsah/obrazy/slideMove.php',
                                data:    'fid='+dragId+'&did='+dropId,
                                success: function(msg){
                                    <?php echo $aJsOnDrop; ?>;
                                    dragDrop();
                                }
                            });
                        }
                    }
                }           
            }
        });

    }

    dragDrop();

    $('.folderListOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel')+'&browse=<?php echo $browse; ?>';
        ajaxElementCall('obrazy_list', '<?php echo $dirPrefixBody; ?>/listBase.php?'+append);
        dragDrop();
        $('.trow1').css('background', 'transparent');
        $('.trow1').css('color', '#3e4245');
        $(this).parent().css('background', "#346cb6 url('img/menuButtonOver.png') left top repeat-x");
        $(this).parent().css('color', 'white');
    });

    $('.rootFolderListOnclick').click(function() {
        window.location = 'navigator.php?kam=obrazy';
        dragDrop();
    });

    $('.folderEditOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel');
        showModal('modal_div', 'Editácia adresára'); 
        ajaxElementCall('modal_div', '<?php echo $dirPrefixBody; ?>/folderEdit.php?kam=edit1&'+append);
    });

    $('.folderDeleteOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel');
        showModal('modal_div', 'Vymazanie adresára'); 
        // TODO 0 Nemam sajnu, aka chyba je tuna - Eclipse mi tu hadze syntax error
        ajaxElementCall('modal_div', '<?php echo $dirPrefixBody; ?>/folderDelete.php?kam=del1&'+append);
    });

    $('.addNewFolder').click(function() {
        showModal('modal_div', 'Nový adresár');
        var id = '<?php echo ToHtml($idFolder); ?>';
        $('.folders .trow1').each(function() {
            if ($(this).css('backgroundColor') == 'rgb(52, 108, 182)' || $(this).css('backgroundColor') == '#346cb6') {
                id = $(this).attr('rel');
            }
        });
        ajaxElementCall('modal_div', 'body/obsah/obrazy/folderAdd.php?idFolder='+id);
    });

});    //-->
</script>

PHP解析后:

<script type="text/javascript">
    //<!--
$(document).ready(function() {

    function in_array (needle, haystack, argStrict) {
        var key = '', strict = !!argStrict; 
        if (strict) {
            for (key in haystack) {
                if (haystack[key] === needle) {
                    return true;            }
            }
        } else {
            for (key in haystack) {
                if (haystack[key] == needle) {
                    return true;
                }
            }
        }
         return false;
    }

    var openedFolders = new Array();
                openedFolders[0] = '3';

    var start = 0;
    var stop = 0;
    $('.drag').each(function() {
        var draggables = $(this).parents('table').find('.drag');
        var $next = draggables.filter(':gt(' + draggables.index(this) + ')').first();
        var width = $(this).css('width');
        var nextWidth = $next.css('width');
        if (nextWidth > width && 30 == parseInt(width)) {
            $(this).removeClass('ordinaryFolderClosed');
            $(this).removeClass('ordinaryFolderOpened');
            if (in_array($(this).attr('rel'), openedFolders)) {
                $(this).addClass('ordinaryFolderOpened');
            } else {
                $(this).addClass('ordinaryFolderClosed');
            }               
        }
        if (in_array($(this).attr('rel'), openedFolders)) {
            start = 1;
        }
        if (1 == start && stop < 2) {               
            if (30 == parseInt(width)) {
                stop++;
            }
        } else {
            start = 0;
            stop = 0;
            if (parseInt(width) > 30) {
                $(this).parent().parent().hide();
            }
        }
    });

    function dragDrop()
    {
        $('.folders .trow1').hover(
            function () {
                if ($(this).css('backgroundColor') != 'rgb(52, 108, 182)' && $(this).css('backgroundColor') != '#346cb6') {
                    $(this).css('background', "#C2E3EF");
                }
            },
            function () {
                if ($(this).css('backgroundColor') != 'rgb(52, 108, 182)' && $(this).css('backgroundColor') != '#346cb6') {
                    $(this).css('background', 'transparent');   
                }
            }
        );

        $('.drag').click(function() {
            var draggables = $(this).parents('table').find('.drag');
            var $next = draggables.filter(':gt(' + draggables.index(this) + ')').first();
            var width = $(this).css('width');
            var nextWidth = $next.css('width');
            if (nextWidth > width && 30 == parseInt(width)) {
                var isVisible = $next.is(':visible');
                if (isVisible) {
                    $(this).removeClass('ordinaryFolderClosed');
                    $(this).removeClass('ordinaryFolderOpened');
                    $(this).addClass('ordinaryFolderClosed');
                } else {
                    $(this).removeClass('ordinaryFolderClosed');
                    $(this).removeClass('ordinaryFolderOpened');
                    $(this).addClass('ordinaryFolderOpened');
                }
                clickedId = $(this).attr('rel');
                $.ajax({
                    type:    'POST',
                    url:     'body/obsah/obrazy/setOpenedFolder.php',
                    data:    'id='+clickedId,
                    success: function(msg){
                        //alert(msg);
                    }
                });
                var start = 0;
                var stop = 0;
                var i = 0;
                $('.drag').each(function() {
                    if (0 == start) {
                        iteratedId = $(this).attr('rel');
                        if (iteratedId == clickedId) {
                            start = 1;
                        }
                    }
                    if (1 == start && stop < 2) {
                        if ($(this).css('width') > width) {
                            if (isVisible) {
                                $(this).parent().parent().hide();
                            } else {
                                $(this).parent().parent().show();
                            }                           
                        } else {
                            stop++;
                        }
                    }
                    i++;
                });
            }
        }); 

        var dragId = 0;
        var dropId = 0;
        var isFile = false;

        $('.drag').mousedown(function() {
            if ($(this).attr('rel') !== undefined) {
                dragId = $(this).attr('rel');
                dragId = dragId.split(',');
                dragId = dragId[0];
            }
            isFile = false;
        });

        $('.drag2').mousedown(function() {
            if ($(this).attr('rel') !== undefined) {
                dragId = $(this).attr('rel');
                dragId = dragId.split(',');
                dragId = dragId[0];
            }
            isFile = true;
        }); 

        $('.drag').draggable({ 
            revert: true,
            cursorAt: {top: 0, left: 0}
        });

        $('.drag2').draggable({
            revert: true,
            cursorAt: {top: 0, left: 0}
        });


        $('.drop').droppable({
            tolerance: 'pointer',
            drop: function() {
                if ($(this).attr('rel') !== undefined) {
                    dropId = $(this).attr('rel');
                    dropId = dropId.split(',');
                    dropId = dropId[0];
                    if (dropId != dragId) {
                        if (false == isFile) {
                            $.ajax({
                                type:    'POST',
                                url:     'body/obsah/obrazy/folderMove.php',
                                data:    'nid='+dragId+'&pid='+dropId,
                                success: function(msg){
                                    ajaxElementCall('__folderList', 'body/obsah/obrazy/folders.php?browse=0&idFolder=', 'obrazy_list', 'body/obsah/obrazy/listBase.php?browse=0&idFolder=');
                                    dragDrop();
                                }
                            });
                        } else if (true == isFile) {
                            $.ajax({
                                type:    'POST',
                                url:     'body/obsah/obrazy/slideMove.php',
                                data:    'fid='+dragId+'&did='+dropId,
                                success: function(msg){
                                    ajaxElementCall('__folderList', 'body/obsah/obrazy/folders.php?browse=0&idFolder=', 'obrazy_list', 'body/obsah/obrazy/listBase.php?browse=0&idFolder=');
                                    dragDrop();
                                }
                            });
                        }
                    }
                }           
            }
        });

    }

    dragDrop();

    $('.folderListOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel')+'&browse=0';
        ajaxElementCall('obrazy_list', 'body/obsah/obrazy/listBase.php?'+append);
        dragDrop();
        $('.trow1').css('background', 'transparent');
        $('.trow1').css('color', '#3e4245');
        $(this).parent().css('background', "#346cb6 url('img/menuButtonOver.png') left top repeat-x");
        $(this).parent().css('color', 'white');
    });

    $('.rootFolderListOnclick').click(function() {
        window.location = 'navigator.php?kam=obrazy';
        dragDrop();
    });

    $('.folderEditOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel');
        showModal('modal_div', 'Editácia adresára'); 
        ajaxElementCall('modal_div', 'body/obsah/obrazy/folderEdit.php?kam=edit1&'+append);
    });

    $('.folderDeleteOnclick').click(function() {
        var append = 'idFolder='+$(this).attr('rel');
        showModal('modal_div', 'Vymazanie adresára'); 
        // TODO 0 Nemam sajnu, aka chyba je tuna - Eclipse mi tu hadze syntax error
        ajaxElementCall('modal_div', 'body/obsah/obrazy/folderDelete.php?kam=del1&'+append);
    });

    $('.addNewFolder').click(function() {
        showModal('modal_div', 'Nový adresár');
        var id = '';
        $('.folders .trow1').each(function() {
            if ($(this).css('backgroundColor') == 'rgb(52, 108, 182)' || $(this).css('backgroundColor') == '#346cb6') {
                id = $(this).attr('rel');
            }
        });
        ajaxElementCall('modal_div', 'body/obsah/obrazy/folderAdd.php?idFolder='+id);
    });

});    //-->
</script>

2 个答案:

答案 0 :(得分:1)

看了整个代码(然后粘贴它,减去PHP内容,进入The Online Lint),我仍然会说Javascript中没有语法错误,如果那样,如果Eclipse告诉你的话那就是Eclipse,那就错了。有时工具并不完美。

代码是否在不同的浏览器中运行?机会相对较好,如果确实如此,那么实际上并没有语法错误。

(根据要求发布答案.Ta。)

答案 1 :(得分:0)

尝试删除引号中的重音字符,您仍然可以输出重音,但使用相应的HTML代码。

可在此处找到重音字符的HTML代码列表:

http://www.w3schools.com/tags/ref_entities.asp