鍍金池/ 問(wèn)答/HTML/ JQ插件編寫(xiě)(面向?qū)ο螅?/span>

JQ插件編寫(xiě)(面向?qū)ο螅?/h1>

我想請(qǐng)教下以下這段JQ插件代碼調(diào)用,

html代碼:

<p class="p1">11111111</p>

JS代碼:

$.fn.hilight = function (options) {
    // 迭代并重新格式化每個(gè)匹配的元素。
    return this.each(function () {
        var $this = $(this);
        // ...
        var markup = $this.html();
        console.log(markup);
        // 調(diào)用格式函數(shù)
        markup = $.fn.hilight.format(markup);
        $this.html(markup);
    });
};
// 定義格式函數(shù)
$.fn.hilight.format = function (txt) {
    return '<strong>' + txt + '</strong>';
};
   

我在調(diào)用的時(shí)候,發(fā)現(xiàn)不對(duì)

$('.p1').hilight('222222');

截圖顯示
clipboard.png

strong 中的txt傳參為什么不顯示了,我沒(méi)發(fā)現(xiàn)問(wèn)題,F(xiàn)12控制臺(tái)未報(bào)錯(cuò)。

回答
編輯回答
練命

markup = $.fn.hilight.format(markup);
改成
markup = $.fn.hilight.format(options);

2017年12月22日 06:46