Uncaught SyntaxError: Unexpected token ILLEGAL after code passes jslint “use strict” check okay

StackOverflow https://stackoverflow.com/questions/12614535

  •  04-07-2021
  •  | 
  •  

Frage

I have the following code from my team mate

/*jslint browser: true*/
/*jslint vars: true */
/*global $, jQuery*/
/*global dialog*/

function accessControls() {
    "use strict";

    $('#loginLink, #registerLink').click(function (e) {
        e.preventDefault();
        if ($(this).data("disabled") === "false") {
            $("a.accessLink").data("disabled", "true");
            dialog(this);
        }
    });

}

Here's the HTML:

<a  class="button accessLink"
            id="loginLink"
            href="#"
            data-action="Login"
            data-dialog="access"
            data-disabled="false"
            data-entity="n/a"
            data-href="/MyAccount/Access/Login"
            title="Login">Login</a>

It's giving me a message in the Chrome browser that says: Uncaught SyntaxError: Unexpected token ILLEGAL. The message comes right after the last semicolon of the code above. Does anyone have any idea what's wrong.

Note that when I comment out the line dialog it works. So is this something to do with the "this" ?

War es hilfreich?

Lösung

if you using equality operator(===) for Boolean variable then you need not to pass false as string

if($(this).data("disabled") === "false"){
// some code
}

need to be changed in

if($(this).data("disabled") === false) {
// some code 
}

anyways if you can post code what is wrapping it that would be better understanding.

and on which jQuery object you are calling dialog()?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top