更多操作
小无编辑摘要 |
小无编辑摘要 |
||
第1行: | 第1行: | ||
// https://stackoverflow.com/questions/14346414/how-do-you-do-html-encode-using-javascript | |||
function htmlEncode(value){ | |||
//create a in-memory div, set it's inner text(which jQuery automatically encodes) | |||
//then grab the encoded contents back out. The div never exists on the page. | |||
return $('<div/>').text(value).html(); | |||
} | |||
$(".WikiaArticle a[title]").hover(function() { | $(".WikiaArticle a[title]").hover(function() { | ||
if (this.className != "") { return; } // 作为 wikilink 的超链接没有 class | if (this.className != "") { return; } // 作为 wikilink 的超链接没有 class | ||
第4行: | 第11行: | ||
var title = a.attr("title"); | var title = a.attr("title"); | ||
if (title != a.text()) { | if (title != a.text()) { | ||
a.append($('<span class="wikilink-popup">' + title + '</span>')); | a.append($('<span class="wikilink-popup">' + htmlEncode(title) + '</span>')); | ||
} | } | ||
}, function() { | }, function() { | ||
$(this).find(".wikilink-popup").remove(); | $(this).find(".wikilink-popup").remove(); | ||
}); | }); |
2018年7月28日 (六) 17:14的版本
// https://stackoverflow.com/questions/14346414/how-do-you-do-html-encode-using-javascript
function htmlEncode(value){
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
//then grab the encoded contents back out. The div never exists on the page.
return $('<div/>').text(value).html();
}
$(".WikiaArticle a[title]").hover(function() {
if (this.className != "") { return; } // 作为 wikilink 的超链接没有 class
var a = $(this);
var title = a.attr("title");
if (title != a.text()) {
a.append($('<span class="wikilink-popup">' + htmlEncode(title) + '</span>'));
}
}, function() {
$(this).find(".wikilink-popup").remove();
});