Javascript 功能赢得';跑不动
我根本无法运行此代码。console.log甚至没有运行。请帮忙Javascript 功能赢得';跑不动,javascript,jquery,Javascript,Jquery,我根本无法运行此代码。console.log甚至没有运行。请帮忙 function showHistory(){ $("#history").text(""); for(var i = 0; i < searchHistory.length; i++){ const historyItem = $("#history").add("<input>");
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")
}
函数showHistory(){
$(“#历史”)。文本(“”);
for(var i=0;i
为了让函数运行,您需要在定义函数后调用它。在您的情况下,应该将行showHistory()添加到文件中。括号表示您正在执行该函数。如果尚未定义searchHistory,则应定义它。此代码均未运行任何内容。它定义了一个函数;它不会执行它。您必须有另一行调用showHistory()
,请尝试将其包装为(function(){//your page initialization code here})()代码>如果您确实调用了该函数,并且出现了错误,请列出它们。我的意思是,该函数在示例中已定义,只是没有被执行/调用