をブロック:リファクタリング:Javascriptがこのコードをリファクタリングいくつかの助けが必要
$("span[rel=color_content]").ColorPicker({
onChange: function (hsb, hex, rg) {
$("span[rel=color_content]").css('background-color', '#' + hex);
}
});
$("span[rel=color_link]").ColorPicker({
onChange: function (hsb, hex, rg) {
$("span[rel=color_link]").css('background-color', '#' + hex);
}
});
$("span[rel=color_selected]").ColorPicker({
onChange: function (hsb, hex, rg) {
$("span[rel=color_selected]").css('background-color', '#' + hex);
}
});
$("span[rel=color_page]").ColorPicker({
onChange: function (hsb, hex, rg) {
$("span[rel=color_page]").css('background-color', '#' + hex);
}
});
$("span[rel=color_player]").ColorPicker({
onChange: function (hsb, hex, rg) {
$("span[rel=color_player]").css('background-color', '#' + hex);
}
});
それぞれの間で変化する唯一のことは、rel
属性の内容です。
+1素晴らしいアイデア... –
素晴らしい解決策! – Shpigford