私はいくつかのフィールドを持っています:
<div class="mystyle">
<input name="font-size" value="12px" />
<input name="font-family" value="Arial" />
<input name="color" Value="#333" />
<button class="setStyle">Save</button>
</div>
を使用していないことに注意してくださいform
。
ボタンをクリックすると、名前をスタイル属性として.setStyle
使用input
し、値を属性値として使用します。
font-size:12px;
font-family:Arial;
color:#333;
を使用して、このスタイルをdivに割り当てます.css()
jQueryでこれを適切に行う方法を教えてください
私はこれを試しました:
jQuery('.setStyle').click(function(){
var parent = jQuery(this).parent('.mystyle');
// now run each inside parent for geting name and value
// run a loop for setting CSS, if value is empty dont add style
}