简体   繁体   中英

Function won't run

I can't get this code to run at all. The console.log doesn't even run. Please help.

function showHistory(){
    $("#history").text("");
    for(var i = 0; i < searchHistory.length; i++){
        const historyItem = $("#history").add("<input>");
        $("historyItem").attr("type","text");
        $("historyItem").attr("readonly",true);
        $("historyItem").attr("class", "form-control d-block bg-white");
        $("historyItem").attr("value", searchHistory[i]);
        $("#history").append(historyItem);
    } 
    console.log("TEST")
}

In order to get a function to run, you need to invoke it after defining it. In your case, you should add the line showHistory() to the file. The parentheses indicate that you are executing the function.

searchHistory should be defined if not already.

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