简体   繁体   English

Javascript-未捕获的SyntaxError:意外的令牌<?

[英]Javascript - Uncaught SyntaxError: Unexpected token <?

Javascript: Javascript:

jQuery(document).ready(function() {
    jQuery('#submit').click(function() {         

        jQuery("#LoadingImage").show();

        var imgSrc = 'http://foo.com/gen.php?username1=' + jQuery('input[name=username1]').val() + '&amp;username2='+ jQuery('input[name=username2]').val();

        jQuery('#imgRESULT').html('<img id="image1" src="' + imgSrc + '" >');
    });

    $('#image1').on("load", (function() {
        $("#LoadingImage").hide();
    });
});

With the html being 随着HTML被

<div id="LoadingImage" style="display: none">
<img src.... /></div>​<div align="center" id="imgRESULT"></div>

and with the correct inputs etc. 以及正确的输入等。

But going into the console I get: 但是进入控制台,我得到:

错误

(Uncaught SyntaxError: Unexpected token <) (未捕获到的SyntaxError:意外的令牌<)

I can't seem to see how to get this script working. 我似乎看不到如何使该脚本正常工作。 Any input? 有输入吗?

                        V--------------extra parenthesis
$('#image1').on("load", (function() {
    $("#LoadingImage").hide(); }); <---extra parenthesis
});

Needs to be: 需要是:

$('#image1').on("load", function() {
    $("#LoadingImage").hide();
});

You have an extra parenthesis before the function statement. 函数语句前有一个额外的括号。 Also switched out jQuery() to $() for appearances. 还将jQuery()切换为$()以获得外观。

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

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