Я хочу поставить условие для элемента jquery в одной части кода в функции. Идея заключается в том, что input.other [type = "checkbox"] не получает такую же возможность, чтобы снять флажок, но получает возможность хорошо выполнять другие действия. вот FiddleПоложить условие для элемента jQuery, внутри функции изменения
HTML
<input type="checkbox" name="accs" icost="5000" class="arms" />Arm 1: $5000
<br/>
<input type="checkbox" name="accs" icost="6000" class="arms" />Arm 2: $6000
<br/>
<input type="checkbox" name="accs" icost="7000" class="neck" />Neck 1: $7000
<br/>
<input type="checkbox" name="accs" icost="8000" class="neck" />Neck 2: $8000
<br/>
<input type="checkbox" name="accs" icost="12000" class="other" />Other 1: $12000
<br />
<input type="checkbox" name="accs" icost="8000" class="other" />Other 2: $20000
<br />
<div id="total">$5000</div>
Javascript код:
var items = $('input.arms[type="checkbox"], input.neck[type="checkbox"], input.other[type="checkbox"]');
// get the initial total and store in a data for use later (resets as needed)
var total = $('#total');
total.data("currentvalue", parseFloat(total.text().replace(/[^0-9\,]+/g, "")));
items.change(function() {
var currenttotal = total.data("currentvalue");
//exlude input.other[type="checkbox"] from here
var myClass = $(this).attr('class');
var thisGroup = $('.' + myClass);
var notme = $('.' + myClass + ':checked').not(this);
var notmeCost = (notme.length ? notme.attr('icost') : ($(this).is(':checked') ? 0 : $(this).attr('icost')));
notme.prop('checked', false);
//ends here
//include input.other[type="checkbox"] from here
currenttotal = currenttotal - notmeCost;
total.fadeOut(300);
thisGroup.filter(':checked').each(function (i) {
var cost = $(this).attr('icost');
currenttotal = currenttotal + parseFloat(cost);
});
total.data("currentvalue", currenttotal);
total.text("$" + currenttotal.formatMoney(0, ',', '.')); // fix your format here as needed
total.fadeIn(300);
});
Что вы хотите? я не понимаю. просьба уточнить. – Sangeeta
Вы хотите, чтобы сумма проверенных товаров была результатом, не так ли? – Sharun
Если вы можете открыть Fiddle, вы сможете увидеть, как он реагирует. В основном, вы можете просто выбрать один флажок из группы, а не два. Мне нужно, чтобы одна из этих групп имела возможность выбирать несколько флажков @Sangeeta –