can't find error in my code?

后端 未结 3 578
予麋鹿
予麋鹿 2021-01-26 07:28

I am making a simple search code. I can\'t find error. The error message says Uncaught SyntaxError: Unexpected identifier on javascript line 40 (target=document.getElement

相关标签:
3条回答
  • 2021-01-26 07:36

    And you have one more comma at the end of script, after }

    0 讨论(0)
  • 2021-01-26 07:54

    You have a comma after that large JSON object you defined at the top of your JavaScript, followed by another var.

    var list= {
     "listOfProducts": [
     {
      "name":"hard disk",
      "price": "50$",
      "quality":"good",
     },
     ...[a bunch of stuff]...
    },
    
    var target=document.getElementById("outputPlace"),
        searchForm=document.getElementById("formSearch"),
        productList=list.listOfProducts,
        listLength=productList.length,
        searchValue=document.getElementById("searchBox"),
        searchInput=searchValue.value;
    

    Both of the two other proposed answers would fix this (well ok Otome deleted their answer which was to drop the second var).

    0 讨论(0)
  • 2021-01-26 07:57

    Change this

    var list = {
       ...
    },
    
    var target=document.getElementById("outputPlace"),
    

    to this:

    var list = {
     ...
    };
    
    var target=document.getElementById("outputPlace"),
    
    0 讨论(0)
提交回复
热议问题