我有一个项目,我使用维基百科的API来检索一些内容。我试图更新一个“点击这里阅读更多链接”动态,但我似乎并没有得到它,我检查了我的代码。这里是我的搜索功能:在jQuery中向动态链接元素添加动态href属性
searchEntry: function (entry)
{
var linker = "http://en.wikipedia.org/wiki/"+entry;
var link = $('<div id="more" contenteditable="true"><p><a href="#" id="morelink">Click here</a> to read more.</p></div>');
$("div#more a").attr("href", linker);
console.log(link);
$.getJSON(wikiSearch.wbase+"action=parse&format=json&prop=text§ion=0&page=" + entry + "&redirects&callback=?", function(data)
{
if (!data.error)
{
var markup = data.parse.text["*"];
if (typeof markup !== "undefined")
{
$("#entry").text(entry).show();
var blurb = $('<div id="articleText"></div>').html(markup);
// remove links as they will not work
blurb.find('a').each(function() { $(this).replaceWith($(this).html()); });
// remove any references
blurb.find('sup').remove();
// remove cite error
blurb.find('.mw-ext-cite-error').remove();
$('#article').html($(blurb).find('p'));
$("#article").append(link);
// console.log(markup);
}
}
else
{
$("#warning").text(data.error.info).show();
}
$(".spinner").hide();
});
$("#article").show();
// if($("#article").show())
// {
// wikiSearch.showMore();
// }
},
非常感谢..它工作 – dejijaye 2014-09-26 07:01:11
很高兴帮助:) – 2014-09-26 17:40:33