简体   繁体   中英

Uncaught SyntaxError: Invalid or unexpected token (​ code getting included in script file)

I have written a very simple index.html file where I have included scripts and also styles

    <!DOCTYPE html>
<html>

<head>
    <title>Image Gallery</title>
    <meta name="viewport" content="width=device-width">
    <link rel="icon" href="images/favicon.ico" type="image/gif" sizes="16x16">
    <link rel="stylesheet" type="text/css" href="css/mediaQuery.css">
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>

<body>
    <script src="js/searchComponent.js"></script>
    <script src="js/service.js"></script>
</body>

</html>

searchComponent.js:

   function Search() {​

}
Search.prototype.fnInitialiseSearchComponent = function() {
    var header = document.createElement("div");
    header.class = 'header';
    $('body').get(0).appendChild(header);
    header.innerHTML = '<input type="text" name="search" id="search-text" placeholder="search images">';
}

When trying to run the application the unicode is getting appended from somewhere and throwing an error

在此处输入图片说明

Any help would be appreciated.

There is an extra character in your code. Remove it and try again. You can see this if you copy the code and past in jsfiddle

在此处输入图片说明

Try this: Delete the entire Search function and retype it.

This will remove any hidden unicode character.

I hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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