Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 除非调试,否则Firefox JS不会运行_Javascript_Firefox_Javascript Events - Fatal编程技术网

Javascript 除非调试,否则Firefox JS不会运行

Javascript 除非调试,否则Firefox JS不会运行,javascript,firefox,javascript-events,Javascript,Firefox,Javascript Events,我有一段简单的代码,它在IE和chrome中都能正常工作,但在firefox中无法工作,除非经过调试 <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-1.7.1.js" > </script> <script> $(document).on("click", "#chb", function () {

我有一段简单的代码,它在IE和chrome中都能正常工作,但在firefox中无法工作,除非经过调试

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.7.1.js" > </script>
<script>
    $(document).on("click", "#chb", function () {
        log("triggered, disabled = " + chb.disabled)
    });
    $(document).on("click", "#go", go);
    cnt = 0;
    function log(msg) {
        $("#log").append("<span>" + ++cnt + ". " + msg + "<br/></span>");
    }
    function go() {
        if (chb.disabled) {
            chb.disabled = null;
            console.log("set to null");
        }
        else {
            chb.disabled = true;
            console.log("set to true");
        }
        fireEvent(chb, "click");
    }
    function fireEvent(element, event) {
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true); // event type,bubbling,cancelable
        return !element.dispatchEvent(evt);
        console.log("Event fired");
    }
</script>
<style>
</style>
</head>
<body>
<input type="checkbox" id="chb">
<input type="button" id="go" value="Go">
<div id="log" />
</body>
</html>

似乎FF无法触发事件。有人知道问题出在哪里吗?

好吧,如果有人偶然发现这个问题。。。问题是它是一只虫子。Firefox中的某个地方存在一个问题,即您无法在再次启用输入、按钮或其他功能后模拟事件。只需使用一个函数,例如,在这种情况下,它如下所示:

    $(document).on("click", "#chb", logg);
     function logg () {
        log("triggered, disabled = " + chb.disabled)
    }
    /// some code here
    function go() {
        if (chb.disabled) {
            chb.disabled = null;
            console.log("set to null");
        }
        else {
            chb.disabled = true;
            console.log("set to true");
        }
        if(!chb.disabled)
             logg()

    }

希望它有帮助

到目前为止,您在调试该问题方面做了哪些工作?控制台是否显示任何错误?问题是,如果对代码进行调试,代码就可以正常工作。它触发fireEvent并添加。但是,当您禁用调试器时,它将无法正常工作。