如何在此函数上添加事件preventDefault,我尝试将其添加到顶部,但是在此函数上不会加载事件preventDefault如何添加它们?我也尝试使用annnymous函数来添加事件preventDefault,但它不起作用....问题是关于如何从请求帖子中删除url或获取,因为一旦我点击任何a然后被哈希触发#我想尝试使用defaultPrevent删除哈希,但它没有用。
$('#search').typeahead({
source: function (query, process) {
$.ajax({
url: URL_SEARCH_PRODUCT,
type: 'POST',
data: {
query: query
},
dataType: 'json',
async: true,
success: function (data) {
process(data);
data.forEach(function (item) {
var options = $("ul.typeahead li");
options.each(function (indice, option) {
if ($(option).find("a").text() === item.name) {
$(option).find("a").attr("data-id", item.id);
$(option).find("a").attr("data-name", item.name);
$(option).find("a").attr("data-qty", item.qty);
$(option).find("a").attr("data-price", item.price);
}
});
});
}
});
},
afterSelect: function (item) {
$("#search").attr("disabled", "disabled");
var actual = $("ul.typeahead li.active a");
var actual_id = $(actual).data("id");
var actual_name = $(actual).data("name");
var actual_qty = 1;
var actual_price = $(actual).data("price");
add_cart(actual_id, actual_name, actual_qty, actual_price, 1);
$("#search").removeAttr("disabled");
}
});
结帐
$("#checkout").click(function (e) {
e.preventDefault();
$("#checkout_pay").validate();
BootstrapDialog.show({
title: '',
message: function (dialog) {
var $message = $('<div></div>');
var pageToLoad = dialog.getData('pageToLoad');
$message.load(pageToLoad);
return $message;
},
data: {
pageToLoad: URL_GET_PAYMANET
},
cssClass: 'payment-dialog',
buttons: [{
label: 'Pay',
cssClass: 'btn-primary',
action: function (dialog) {
if ($("#checkout_pay").valid()) {
BootstrapDialog.confirm({
title: '',
message: 'Deseas completar la orden?',
type: BootstrapDialog.TYPE_WARNING,
closable: false,
btnCancelLabel: 'no',
btnOKLabel: 'yes',
btnOKClass: 'btn-warning',
callback: function (result) {
if (result) {
var total = $("#amount_tendered").val();
var cantidad_pagada = $("#cantidad_pagada").val();
if (Number(cantidad_pagada) >= Number(total)) {
var datos_formulario = new FormData();
datos_formulario.append("total", total);
datos_formulario.append("cantidad_pagada", cantidad_pagada);
$.ajax({
url: URL_SELL_CART,
method: 'POST',
data: datos_formulario,
processData: false,
contentType: false,
success: function (data) {
if (data == 1) {
$.ajax({
url: URL_GET_CART,
method: 'POST',
dataType: 'json',
success: function (data) {
setCartHtml(data);
}
});
BootstrapDialog.show({
type: BootstrapDialog.TYPE_SUCCESS,
message: 'Sale completed!, the change due is: ' + (Number(cantidad_pagada) - Number(total))
});
} else {
BootstrapDialog.show({
type: BootstrapDialog.TYPE_DANGER,
message: 'please enter the money before accept'
});
}
}
});
} else {
BootstrapDialog.show({
type: BootstrapDialog.TYPE_DANGER,
message: 'The payment must be equal or higher than the total'
});
}
return false;
} else {}
}
});
}
}
}]
});
});