我有一个如下所示的食谱应用程序:http: //i.stack.imgur.com/FxL7R.png
在成分范围的末尾是一个删除按钮。出于某种原因,我的代码不起作用(这意味着它没有删除成分范围):
HTML:
<div class='formelementcontainer funky'>
<label for="ingredient">Ingredients</label>
<div id='ingredientsCOUNT' class='sortable'>
<span>
<input type="text" class='small' name="ingredient" id="ingredient" placeholder='QTY'/>
<select name='measurements'>
<option value='' name='' checked='checked'>--</option>
<?foreach ($measurements as $m):?>
<option value='<?=$m->id;?>'><?=$m->measurement;?></option>
<?endforeach;?>
</select>
<input type="text" name="ingredient" id="ingredient" placeholder='Ingredient'/>
<a class='float-right delete-button' id='deleteThis' style='margin:10px 2px;' href='#'><img src='<? echo base_url()."public/img/delete.png";?>' height='11' width='11' /></a>
</span>
</div>
<div class="clear"></div>
<div class='addSPAN tabover'>
<a class='float-right' id='btnAddIngredients' href='#'>Add Ingredient</a>
</div>
</div>
查询:
(function($) {
$(document).ready(function () {
$('#btnAddIngredients').click(function () {
var num = $('#ingredientsCOUNT span').length;
var newNum = new Number(num + 1);
$('#ingredientsCOUNT > span:first')
.clone()
.attr('name', 'ingredient' + newNum)
.appendTo('#ingredientsCOUNT')
.fadeIn();
});
$('#deleteThis').click(function () {
var span = $(this).closest('span');
span.fadeOut('slow', function() { span.remove(); });
});
});
})(jQuery);
应该发生的是当我点击X时,最近的跨度(包含跨度)被删除。但是当我点击它时,什么也没有发生。有什么建议么?感谢大家的帮助!
编辑
这是一个 JSFIDDLE:http: //jsfiddle.net/sjDk7/1/