我有以下 jQuery,我必须在选择列表项时禁用其他列表的某些项。一切正常,现在我坚持的一点是我必须选择一些列表,所以我已经给出了条件,但是当我返回 true 时它执行 jQuery 两次,并且功能启用禁用停止正常工作,但是当我返回 true,启用禁用工作更正但单选选项无法正常工作
.delegate('input[type="checkbox"], input[type="radio"]', 'click.multiselect', function (e) {
var $this = $(this);
var val = this.value;
var checked = this.checked;
var tags = self.element.find('option');
// bail if this input is disabled or the event is cancelled
if (this.disabled || self._trigger('click', e, {
value: val,
text: this.title,
checked: checked
}) === false) {
e.preventDefault();
return;
}
//filter(':checked')
// Remove from Y single Y multiple Y2 Multiple Datacolumn if selected in X
if (val.indexOf("ltrXaxis") >= 0) {
if ($('#lsltrXaxis option').filter(':checked').length > 0 && checked == true) {
// alert('Maximum One can be selected');
return true;
}
var val1 = val.replace("ltrXaxis", "ltrXYAxis");
var val2 = val.replace("ltrXaxis", "ltrYMaxis");
var val3 = val.replace("ltrXaxis", "ltrY2axis");
var val4 = val.replace("ltrXaxis", "ltrSeriesColumn");
var val5 = val.replace("ltrXaxis", "ltrDataColumn");
if (checked == true) {
$('#lsltrXYAxis , :input[value="' + val1 + '"]').attr({
'disabled': true,
'aria-disabled': true,
'checked': false,
'aria-selected': false
}).addClass('ui-state-disabled');
$('#lsltrYMaxis , :input[value="' + val2 + '"]').attr({
'disabled': true,
'aria-disabled': true,
'checked': false,
'aria-selected': false
}).addClass('ui-state-disabled');
$('#lsltrY2axis , :input[value="' + val3 + '"]').attr({
'disabled': true,
'aria-disabled': true,
'checked': false,
'aria-selected': false
}).addClass('ui-state-disabled');
$('#lsltrDataColumn , :input[value="' + val5 + '"]').attr({
'disabled': true,
'aria-disabled': true,
'checked': false,
'aria-selected': false
}).addClass('ui-state-disabled');
} else {
$('#lsltrXYAxis , :input[value="' + val1 + '"]').attr({
'disabled': false,
'aria-disabled': false
}).removeClass('ui-state-disabled');
$('#lsltrYMaxis , :input[value="' + val2 + '"]').attr({
'disabled': false,
'aria-disabled': false
}).removeClass('ui-state-disabled');
$('#lsltrY2axis , :input[value="' + val3 + '"]').attr({
'disabled': false,
'aria-disabled': false
}).removeClass('ui-state-disabled');
$('#lsltrDataColumn , :input[value="' + val5 + '"]').attr({
'disabled': false,
'aria-disabled': false
}).removeClass('ui-state-disabled');
}
return true;
}
// Remvoe From DataCoulumn If selected in Y Single
if (val.indexOf("XYAx") >= 1) {
if ($('#lsltrXYAxis option').filter(':checked').length > 0 && checked == true) {
// alert('Maximum One can be selected');
return true;
}
var val5 = val.replace("ltrXYAxis", "ltrDataColumn");
if (checked == true) {
$('#lsltrDataColumn , :input[value="' + val5 + '"]').attr({
'disabled': true,
'aria-disabled': true,
'checked': false,
'aria-selected': false
}).addClass('ui-state-disabled');
} else {
$('#lsltrDataColumn , :input[value="' + val5 + '"]').attr({
'disabled': false,
'aria-disabled': false
}).removeClass('ui-state-disabled');
}
return true;
}
// Remove From Y2 Multiple If selected in Y Multiple
if (val.indexOf("YMax") >= 1) {
var val3 = val.replace("ltrYMaxis", "ltrY2axis");
if (checked == true) {
$('#lsltrY2axis , :input[value="' + val3 + '"]').attr({
'disabled': true,
'aria-disabled': true,
'checked': false,
'aria-selected': false
}).addClass('ui-state-disabled');
} else {
$('#lsltrY2axis , :input[value="' + val3 + '"]').attr({
'disabled': false,
'aria-disabled': false
}).removeClass('ui-state-disabled');
}
return true;
}
// Return False if DataColumn selected More than 1
if (val.indexOf("ltrDataColumn") >= 1) {
if ($('#lsltrDataColumn option').filter(':checked').length > 0 && checked == true) {
// alert('Maximum One can be selected');
return true;
}
}
// Return False if Series Column selected More than 1
if (val.indexOf("trSeries") >= 1) {
if ($('#lsltrSeriesColumn option').filter(':checked').length > 0 && checked == true) {
// alert('Maximum One can be selected');
return true;
}
}
// make sure the input has focus. otherwise, the esc key
// won't close the menu after clicking an item.
$this.focus();
// toggle aria state
$this.attr('aria-selected', checked);
// change state on the original option tags
tags.each(function () {
if (this.value === val) {
this.selected = checked;
} else if (!self.options.multiple) {
this.selected = false;
}
});
// some additional single select-specific logic
if (!self.options.multiple) {
self.labels.removeClass('ui-state-active');
$this.closest('label').toggleClass('ui-state-active', checked);
// close menu
self.close();
}
// fire change on the select box
self.element.trigger("change");
// setTimeout is to fix multiselect issue #14 and #47. caused by jQuery issue #3827
// http://bugs.jquery.com/ticket/3827
setTimeout($.proxy(self.update, self), 10);
});
主要问题是在返回真假之后,一些代码正在执行,
我究竟做错了什么?