繁体   English   中英

如何修复此错误“丢失;在声明之前“在javascript中?

[英]How can I fix this error “missing; before statement” in javascript?

如何在javascript中修复此错误“missing; before statement”?

替代文字

我的HTML页面: http//etrokny.faressoft.com

我的Javascript代码: http//etrokny.faressoft.com/javascript.php

在所有陈述之后加上分号。 当你在一行结束时“忘记”一个时,JavaScript会自动为你做**,但由于你使用了一个工具使一切都适合一行,所以这种情况不再发生了。

**当一个陈述后跟一个}时也应该发生,但依靠它是不好的做法。 我总是自己写所有的分号。

实际上,你知道什么,因为它很容易,我为你做了:

function getSelected() {
    var selText;
    var iframeWindow = window;
    if (iframeWindow.getSelection) {
        selText = iframeWindow.getSelection() + "";
    } else if (iframeWindow.document.selection) {
        selText = iframeWindow.document.selection.createRange().text;
    }
    selText = $.trim(selText);
    if (selText != "") {
        return selText;
    } else {
        return null;
    }
}
$(document).ready(function () {
    function scan_selectedText() {
        if (getSelected() == null) {
            return false;

        }
        if (getSelected().length < 25) {
            return false;
        }
        $(document)[0].oncontextmenu = function () {
            return false;
        };
        var result = true;
        var selected_Text = getSelected();
        selected_Text = selected_Text.replace(/ {2,}/g, ' ').replace(/\s{2,}/g, ' ');
        $('#content .para').each(function () {
            var accepted_text = $.trim($(this).text());
            accepted_text = accepted_text.replace(/ {2,}/g, ' ').replace(/\s{2,}/g, ' ');
            if (accepted_text.search(selected_Text) > -1) {
                result = false;
            }
        });
        var AllAccepted = "";
        $('#content .para').each(function () {
            var correntDiv = $.trim($(this).text()).replace(/ {2,}/g, ' ').replace(/\s{2,}/g, ' ');
            AllAccepted = AllAccepted + correntDiv + " ";
        });
        if ($.trim(AllAccepted).search(selected_Text) > -1) {
            return false;
        }
        if (!result) {
            return false;
        }
        var body = $.trim($('body').text());
        body = body.replace(/ {2,}/g, ' ').replace(/\s{2,}/g, ' ');
        var bodyWithoutDivs = body;
        $('#content').each(function () {
            var correntDiv = new RegExp($.trim($(this).text()).replace(/ {2,}/g, ' ').replace(/\s{2,}/g, ' '), "");
            bodyWithoutDivs = bodyWithoutDivs.replace(correntDiv, '');
        });
        if (bodyWithoutDivs.search(selected_Text) > -1) {
            return false;
        }
        if (body == selected_Text) {
            return true;
        }
        return true;
    }
    $(document).mousedown(function (key) {
        if (key.button == 2) {
            if (scan_selectedText() == true) {
                $(document)[0].oncontextmenu = function () {
                    return false;
                };
            } else {
                $(document)[0].oncontextmenu = function () {
                    return true;
                };
            }
        }
    });
    var isCtrl = false;
    $(document).keyup(function (e) {
        if (e.which == 17) isCtrl = false;
    }).keydown(function (e) {
        if (e.which == 17) isCtrl = true;
        if (e.which == 67 && isCtrl == true) {
            $("#content2").animate({
                opacity: 0
            }, 500).animate({
                opacity: 1
            }, 500);
            if (scan_selectedText() == true) {
                return false;
            } else {
                return true;
            }
        }
    });
    document.onkeypress = function (evt) {
        if (evt.ctrlKey == true && evt.keyCode == 67) {
            $("#content2").animate({
                opacity: 0
            }, 500).animate({
                opacity: 1
            }, 500);
            if (scan_selectedText() == true) {
                return false;
            } else {
                return true;
            }
        }
    };
    $('*').bind('copy', function (key) {
        if (scan_selectedText() == true) {
            return false;
        } else {
            return true;
        }
    });
});

将函数赋值给变量时,在函数后需要一个分号。

示例: var func = function() { return false; }; var func = function() { return false; };

首先,从你的javascript的原始人工编写版本开始,你知道,非机器生成的非机器版本

在你修复之后你已经确定它没有语法错误....并且你最小化它,在复制/粘贴时不要犯错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM