「if (color[0] == '_') { return; }」の箇所がよく分かりません。
「jquery.color.svg-names.js」より、「$.Color.names」は
Colorオブジェクトのプロパティnamesは色名に対応したカラーコードを設定した
オブジェクトであることは理解出来ています。
ですがアンダースコア(_)と比較することに何の意味があるのかが全く分かりません。
アドバイスをお願い致します。
該当のソースコード
HTML
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="UTF-8"> 5 <title></title> 6</head> 7<body> 8 <div> 9 <h4>jQuery Color Pluginの機能</h4> 10 <div id="border"></div> 11 <form id="form" onsubmit="return false;"></form> 12 </div> 13<script src="js/jquery-3.6.0.min.js"></script> 14<script src="js/jquery.easing.min.js"></script> 15<script src="js/jquery.color.js"></script><!-- jQuery Color Plugin --> 16<script src="js/app.js"></script> 17</body> 18</html>
jQuery
1// 改訂新版jQuery本格入門 P175のコードより。 2 3(function($) { 4 5 // 要素のスタイル(CSS) 6 $('#border').css({ 7 'border' : '25px solid black', 8 'marginBottom' : 10 9 }); 10 11 // ラジオボタンの設定 12 $.each($.Color.names, function(color) { 13 if (color[0] == '_') { return; } // 疑問の箇所 14 const label = $('<label>', { 15 'for' : color, 16 'text' : color 17 }).appendTo('#form'); 18 $('<input>', 19 { 20 click() { 21 22 // クリックされたラジオボタンの色に変化させる 23 $('#border').animate( 24 { 'borderColor' : $(this).val() }, 25 { 26 'easing' : 'easeOutQuad', 27 'speed' : 'fast' 28 } 29 ); 30 }, 31 'id' : color, 32 'name' : 'color', 33 'type' : 'radio', 34 'val' : color 35 } 36 ).prependTo(label); 37 }); 38})(jQuery);
jQuery
1// jQuery Color Plugin 2 3jQuery.extend(jQuery.Color.names, { 4 5 // 4.3. Extended color keywords (minus the basic ones in core color plugin) 6 aliceblue : "#f0f8ff", 7 antiquewhite : "#faebd7", 8 aquamarine : "#7fffd4", 9 azure : "#f0ffff", 10// 中略 11 whitesmoke : "#f5f5f5", 12 yellowgreen : "#9acd32" 13});
回答2件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2022/09/23 07:07