我正在嘗試使用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);
});
}
});