当我单击 .edit-one-button 按钮时,我想删除 .widget 框的样式。我有六个盒子和六个按钮。当我尝试使用下面的 javascript 时。单击一个按钮将删除所有框的样式。我应该怎么做才能只影响单击按钮时按钮所在的框?
<script type="text/javascript">
var divheight;
$(".edit-one-button").click(function () {
var btnname = $(this).val();
if (btnname == 'Edit') {
divheight = $('.widget').attr('style');
$('.widget').removeAttr('style');
$(this).nextUntil('.edit-one-button').toggle();
}
else {
$(this).nextUntil('.edit-one-button').toggle();
$('.widget').attr('style', divheight);
}
});
</script>
HTML:
<div class="eq-height2 widget>
<header>
<h2>Contact1</h2>
</header>
<input type="submit" value="Edit" class="edit-one-button/>
<fieldset id="Fieldset1">
blabla
</fieldset>
<fieldset id="Fieldset2">
blabla
</fieldset>
</div>
<div class="eq-height2 widget>
<header>
<h2>Contact2</h2>
</header>
<input type="submit" value="Edit" class="edit-one-button/>
<fieldset id="Fieldset3">
blabla
</fieldset>
<fieldset id="Fieldset4">
blabla
</fieldset>
</div>
<div class="eq-height2 widget>
<header>
<h2>Contact3</h2>
</header>
<input type="submit" value="Edit" class="edit-one-button/>
<fieldset id="Fieldset5">
blabla
</fieldset>
<fieldset id="Fieldset6">
blabla
</fieldset>
</div>