2 回答

TA貢獻1876條經驗 獲得超7個贊
在 jQuery 中,您可以綁定所有輸入更改
$('.order_form input').change(functon(){
var $form = $('.order_form');
#code for compare previous value with changing value
$.ajax( {
type: $form.attr('method'),
url : "/buyer/ajax/compare_form_add_cart",
dataType : "json",
data : $form.serialize(),
success : function(resultdata) {
if(resultdata){
if(confirm("Do you want to save your changes?")){
#if confirm yes
$.ajax({
type: 'post',
url: '/buyer/Ajax/add_order_data_in_cart_session',
data: $('.order_form').serialize(),
dataType: 'json',
success: function(res, textStatus, xhr){
if(res.result) {
location.href = link;
} else {
$( "#loading_layer" ).css('display', 'none');
alert('Failed to save cart data. Please try again.');
}
}
});
}else{
#if confirm not
location.href = link;
};
}else{
return true;
}
}
});
})

TA貢獻1802條經驗 獲得超6個贊
例如,您需要復制輸入字段
// Input Field (TEXT)
< input type="text" id="input1" value="Same Value" />
// Hidden Input for comparison
< input type="hidden" value="Same Value" />
在點擊功能上,您應該比較這些字段,例如
function ExitCart(link){
// Get Input Value
var val = $.trim($('#input1').val());
// Get Reference Value from next input
var valChk = $.trim($('#input1').next().val());
if(val != valChk) {
YOUR CODE HERE
}
}
- 2 回答
- 0 關注
- 165 瀏覽
添加回答
舉報