0
我試圖刪除被附加到HTML特定A HREF標籤:追加和刪除特定元素
的jQuery:
首先函數生成的鏈接:
var edit_link = function (id, price) {
var args = ('<a target="_blank" class="tag-res" href="/reservations/database/edit/'+id+'">Res: '+id+ '('+price+')</a>');
return args;
}
其次追加在選擇值時鏈接。
var ajaxHandler = function(decrement) {
return function(value){
$.ajax({
type: 'GET',
url: '/police/get_res_price?price=' + value,
success: function (data) {
var initial_price = parseInt($('.give-me-money').val());
var obj = JSON.parse(data);
$.each(obj, function (booking_price, value) {
if (decrement) {
initial_price -= parseInt(value.BOOKING_PRICE);
$(edit_link(value.DBASE_ID, value.BOOKING_PRICE)).remove();
} else {
//case booking is null alert
if (value.BOOKING_PRICE === 0 || value.BOOKING_PRICE <= 0) {
alert('There is a problem with Reservation: ' + value.DBASE_ID + '\n\nProblem: Price is 0');
}
initial_price += parseInt(value.BOOKING_PRICE);
$('div[name=res_list]').removeClass('hidden');
$('.res_selected_list').append(edit_link(value.DBASE_ID, value.BOOKING_PRICE));
}
});
$('.give-me-money').val(initial_price); //set total
}
});
this.qs1.cache();
this.qs2.cache();
}
}
HTML:
<div name="res_list" class="row-space-2 form-group hidden">
<label class="col-md-3 control-label" for="inputTooltip">Selected reservations:</label>
<div class="col-md-6 res_selected_list"></div>
</div>
追加工作正常,但試圖以刪除每個附加元素:$(edit_link(value.DBASE_ID, value.BOOKING_PRICE)).remove();
沒什麼一切發生的時候。建議?
就像我想將數據添加屬性爲HTML,謝謝! –