开发者

jQuery Buttons with icons, is there a better way to rewrite this

Is there a better shorter way to rewrite the code. I have 10 of those buttons each wit开发者_运维知识库h a different icon.

$("#Text").button({
    icons: {
        primary: "ui-icon-locked"
    }
});

$("#Text1").button({
    icons: {
        primary: "ui-icon-gear"
    }
});

$("#Text2").button({
    icons: {
        primary: "ui-icon-comment"
    }
});


You could create an id to icon class mapping object and then iterate over it:

var mapping = {
    "Text" : "ui-icon-locked",
    "Text1" : "ui-icon-gear",
    "Text2" : "ui-icon-comment"
};

$.each(mapping, function(id, icon) {
    $('#' + id).button({ icons : { primary : icon } });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜