我试图将多个值相加为一个值,并将其附加到输入值中。更新的jQuery:
afterSelect: function(value){
$.ajax({
type: 'GET',
url: '/police/get_res_price?price=' + value,
success: function (data) {
var initial_price = $('.give-me-money').val();
var obj = JSON.parse(data);
$.each(obj, function(booking_price, value) {
initial_price += value.BOOKING_PRICE;
});
$('.give-me-money').val(initial_price); //set total
console.log(initial_price);
}
});
this.qs1.cache();
this.qs2.cache();
},HTML:
<select id='custom-headers' multiple='multiple' class="searchable">
<?php foreach ($get_reservations as $res_option): ?>
<option value="<?php print $res_option->DBASE_ID; ?>"><?php print $res_option->DBASE_ID; ?></option>
<?php endforeach; ?>
</select>
<input class="give-me-money" type="text">每次单击log号码,例如,5117,547,987,54。并将其附加到multiselect的最后一个选择的输入中。我想说“等待”和5117+547+987+54,并将6705附加到输入值中,我将如何做到这一点?
发布于 2015-11-16 15:08:37
您需要将所有值添加到同一个变量,然后将值设置为.give-me-money字段。还可以更改html:
html
<input class="give-me-money" type="text" value="0">javascript
afterSelect: 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) {
console.log(value.BOOKING_PRICE);
initial_price += parseInt(value.BOOKING_PRICE);
});
$('.give-me-money').val(initial_price); //set total
}
});
this.qs1.cache();
this.qs2.cache();
}发布于 2015-11-16 15:46:58
显示聊天代码:
afterSelect: function(value){
$.ajax({
type: 'GET',
url: '/police/get_res_price?price=' + value,
success: function (data) {
var initial_price = parseInt($('.give-me-money').val(), 10) || 0;
var obj = JSON.parse(data);
$.each(obj, function(booking_price, value) {
initial_price += parseInt(value.BOOKING_PRICE, 10);
});
$('.give-me-money').val(initial_price); //set total
console.log(initial_price);
}
});
this.qs1.cache();
this.qs2.cache();
},https://stackoverflow.com/questions/33738357
复制相似问题