我正在尝试使用Jetpack,我想解析给定html页面中的所有年份,然后用链接指向Wiki页面来包装年份。我尝试了jquery中的代码,它在那里工作,但现在我在Jetpack中使用它,它给出了一个错误$(doc).replace不是一个函数。我绝对是Jquery/Jetpack的新手,所以也许我错过了一些非常简单的事情,但是非常感谢您的帮助。让jQuery在Jetpack中工作
编辑:我试过这些建议,但我仍然卡住。奇怪的是,这
jQuery函数工作:
(function($) {
$.fn.clickUrl = function() {
var regexp = /([1-2][0-9][0-9][0-9])/gi;
this.each(function() {
$(this).html(
$(this).html().replace(regexp,'<ahref=\"http://nl.wikipedia.org/wiki/$1\">$1<\/a>')
);
});
return $(this);
}
})(jQuery);
,基本上,我想“口”这个功能Jetpack的。
这是“老”非工作我的JQuery功能来Jetpack的端口:
jetpack.statusBar.append({
html: "Hyperlink Years",
width: 80,
onReady: function(widget){
$(widget).click(function(){
var regexp = /([1-2][0-9][0-9][0-9])/gi;
var doc = jetpack.tabs.focused.contentDocument;
$(doc).each(function() {
$(this).html(
$(doc).replace(regexp,'<a href=\"http://nl.wikipedia.org/wiki/$1\">$1<\/a>'));
});
return $(doc);
});
}
});