我正在尝试将变量mySearchTitle
传递给函数以便阅读page: mySearchTitle
var mySearchTitle;
$("#wikiResults li a").on("click", function(e) {
e.preventDefault();
mySearchTitle = $(this).html().replace(/ /g,"_");
console.log($(this).html().replace(/ /g,"_"));
textWiki(mySearchTitle);
});
}
function textWiki() {
$.getJSON("https://"+ queryLang +".wikipedia.org/w/api.php?action=parse&disablelimitreport=true&format=json&prop=text&limit=1&callback=?", {
page: mySearchTitle
但我进入控制台
Uncaught ReferenceError: mySearchTitle is not defined
答案 0 :(得分:0)
要在函数中使用变量,您需要将其作为参数传递给函数
function textWiki(mySearchTitle){
//use mySearchTitle as needed
}