1
問題似乎是財產 '文':遺漏的類型錯誤:無法讀取的不確定(...)
$("#results").append("<div class='list-group'><a class='list-group-item' href='https://it.wikipedia.org/wiki/" + encodeURIComponent(item.title.replace(" ", "_")) + "' data-toggle='modal' data-target='.bs-example-modal-lg'><h4>" + item.title.replace(" ", "_") + "</h4><p class='list-group-item-text'>" + item.snippet + "</p></a></div>");
而且它的呼叫
page: e.relatedTarget.textContent,
Hit the button Wikipedia, get the results, click on a result = should load its wikipedia page: JSFiddle playground
下面有它:
$("#wiki").one('click', function(e) {
var articleName = $(this).data('subject');
$.getJSON("https://it.wikipedia.org/w/api.php?callback=?", {
srsearch: articleName,
action: "query",
list: "search",
format: "json"
}, function(data) {
$("#results ul").empty();
$("#results ul").append("<h3>Results for <b>" + articleName + "</b></h3>").text();
$.each(data.query.search, function(i, item) {
$("#results").append("<div class='list-group'><a class='list-group-item' href='https://it.wikipedia.org/wiki/" + encodeURIComponent(item.title.replace(" ", "_")) + "' data-toggle='modal' data-target='.bs-example-modal-lg'><h4>" + item.title.replace(" ", "_") + "</h4><p class='list-group-item-text'>" + item.snippet + "</p></a></div>");
$("#results div a").attr("href", "#");
});
$('.modal').on('show.bs.modal', function (e) {
$.getJSON("https://it.wikipedia.org/w/api.php?action=parse&format=json&callback=?", {
page: e.relatedTarget.textContent,
prop:"text"
}, function(data) {
$(".modal-content").html(data.parse.text['*']);
});
});
});
});
儘管這個工程,但我需要上述的一個由於HTML無線薄呢:
$("#wiki").one('click', function(e) {
var articleName = $(this).data('subject');
$.getJSON("https://it.wikipedia.org/w/api.php?callback=?", {
srsearch: articleName,
action: "query",
list: "search",
format: "json"
}, function(data) {
$("#results ul").empty();
$("#results ul").append("<h3>Results for <b>" + articleName + "</b></h3>").text();
$.each(data.query.search, function(i, item) {
$("#results").append("<a class='list-group-item' href='https://it.wikipedia.org/wiki/" + encodeURIComponent(item.title.replace(" ", "_")) + "' data-toggle='modal' data-target='.bs-example-modal-lg'><h4>" + item.title.replace(" ", "_") + "</h4><p class='list-group-item-text'>" + item.snippet + "</a>");
$("#results div a").attr("href", "#");
});
$('.modal').on('show.bs.modal', function (e) {
$.getJSON("https://it.wikipedia.org/w/api.php?action=parse&format=json&callback=?", {
page: e.relatedTarget.textContent,
prop:"text"
}, function(data) {
$(".modal-content").html(data.parse.text['*']);
});
});
});
});
你重置''到''#兩倍以上這些行:'$('#DIV結果a')。attr('href','#');' - 這意味着它試圖從''取代而不是與維基百科文章的鏈接。首先解決它。 – junkfoodjunkie
@junkfoodjunkie謝謝,修正了這一點。但問題在於那裏。問題和JSFdille更新 –