keyup イベントを使用して、jquery を介してテキスト フィールドにテキストをロードしようとしています。テキストは json を介して取得し、変数「値」に格納する必要があります。json に保存されているテキストをこの変数に入れるにはどうすればよいですか? 私はこれを試しましたが、うまくいきません:
var value = html(json['total']);
以下のjqueryコードの関連部分を抽出しました。ありがとう。
var Run;
$('input[name*=\'quantity\']').keyup(function(e){
ctrl = $(this);
$('.loading').remove();
ctrl.before('<img class="loading" src="catalog/view/theme/default/image/loading.gif" alt="" />');
clearTimeout(Run);
Run = setTimeout(function(){
if (!ctrl.val() || ctrl.val() == 0) {
$('.loading').remove();
ctrl.val(qty);
return false;
}
$.ajax({
url: 'index.php?route=checkout/cart/quantity',
type: 'post',
data: ctrl,
dataType: 'json',
success: function(json){
row = ctrl.parent().parent();
ctrl.parent().css('width',ctrl.parent().width());
$('#content h1').html(json['cart_heading']);
$('#cart_total').html(json['header_cart_total']);
var value = html(json['total']);
row.find('.total').html(json['total']);
row.find('.price').html(json['price']);
row.find('.total').prepend('<input type="text" value="' + value + '" name="total" />');
html='';
for (i in json['totals']) {
html += '<tr>';
html += '<td colspan="5"></td>';
html += '<td class="right"><b>' + json['totals'][i]['title'] + '</b></td>';
html += '<td class="right">' + json['totals'][i]['text'] + '</td>';
html += '</tr>';
}
$('.cart-total table').fadeOut(500,function(){
$('.cart-total table tr').remove();
$('.cart-total table').append(html).fadeIn(500);
});
$('.loading').remove();
}
});
},800);
});