在此之后,我必须在单击事件上一个一个地添加 2 个 div,添加按钮将被禁用,当我删除第一个或第二个添加的 div 时,添加按钮将被启用这是我的代码.. 这是jsfiddle
HTML
<a id="addMoreroom" class="fnt-size13" href="#">+ Add Rooms</a>
<div id="roomDiv-1" class="rowG clearfix hide">
<label>Selected Room Type</label>
<select>
<option>1</option>
</select>
<label>Number Of Rooms</label>
<select>
<option>3</option>
</select>
<a id="rmoveRoom_1" class="fnt-size13" href="#">- Remove</a>
</div>
<div id="roomDiv-2" class="rowG clearfix hide">
<label>Selected Room Type</label>
<select>
<option>1</option>
</select>
<label>Number Of Rooms</label>
<select>
<option>3</option>
</select>
<a id="rmoveRoom_2" class="fnt-size13" href="#">- Remove</a>
</div>
jQuery
$("#addMoreroom").click(function () {
$('#roomDiv-1').addClass('show');
$('#addMoreroom').attr('id', 'addMoreroom1');
$("#addMoreroom1").click(function () {
$('#roomDiv-2').addClass('show');
$(this).hide();
return false;
});
});
$("#rmoveRoom_1").click(function () {
$('#roomDiv-1').remove();
$('#addMoreroom1').show();
return false;
});
$("#rmoveRoom_2").click(function () {
$('#roomDiv-2').remove();
$('#addMoreroom').show();
$('#addMoreroom1').attr('id', 'addMoreroom');
return false;
});
});
问题是每当我单击删除按钮时,循环都会被吸走并且添加按钮将不可见请给我一些建议..