所以我有一系列的按鈕,我用來關閉所有複選框的每一天,這一刻看起來很雜亂,所以我會就像把所有的按鈕變成一個下拉選擇字段,將選項更改爲星期一,例如運行星期一jquery以隱藏所有的星期一複選框。在選擇下拉更改隱藏/顯示覆選框取決於選項的價值
下面是HTML
<input type='submit' name='submit_performances' value='update all'>
<input type='button' id='select-all-toggle' name='select-all-toggle' value='Hide/Show all Performances'>
<input type='button' id='select-all-toggle-monday' name='select-all-toggle-monday' value='Hide/Show all Monday Performances'>
<input type='button' id='select-all-toggle-tuesday' name='select-all-toggle-tuesday' value='Hide/Show all Tuesday Performances'>
<input type='button' id='select-all-toggle-wednesday' name='select-all-toggle-wednesday' value='Hide/Show all Wednesday Performances'>
<input type='button' id='select-all-toggle-thursday' name='select-all-toggle-thursday' value='Hide/Show all Thursday Performances'>
<input type='button' id='select-all-toggle-friday' name='select-all-toggle-friday' value='Hide/Show all Friday Performances'>
<input type='button' id='select-all-toggle-saturday' name='select-all-toggle-saturday' value='Hide/Show all Saturday Performances'>
<input type='button' id='select-all-toggle-sunday' name='select-all-toggle-sunday' value='Hide/Show all Sunday Performances'>
</form>
這裏是jQuery的
<script>
$(document).ready(function() {
$('#select-all-toggle').toggle(
function() {
$('.select-all-identifier').prop('checked', true);
},
function() {
$('.select-all-identifier').prop('checked', false);
}
);
});
$(document).ready(function() {
$('#select-all-toggle-monday').toggle(
function() {
$('.monday').prop('checked', true);
},
function() {
$('.monday').prop('checked', false);
}
);
});
$(document).ready(function() {
$('#select-all-toggle-tuesday').toggle(
function() {
$('.tuesday').prop('checked', true);
},
function() {
$('.tuesday').prop('checked', false);
}
);
});
$(document).ready(function() {
$('#select-all-toggle-wednesday').toggle(
function() {
$('.wednesday').prop('checked', true);
},
function() {
$('.wednesday').prop('checked', false);
}
);
});
$(document).ready(function() {
$('#select-all-toggle-thursday').toggle(
function() {
$('.thursday').prop('checked', true);
},
function() {
$('.thursday').prop('checked', false);
}
);
});
$(document).ready(function() {
$('#select-all-toggle-friday').toggle(
function() {
$('.friday').prop('checked', true);
},
function() {
$('.friday').prop('checked', false);
}
);
});
$(document).ready(function() {
$('#select-all-toggle-saturday').toggle(
function() {
$('.saturday').prop('checked', true);
},
function() {
$('.saturday').prop('checked', false);
}
);
});
$(document).ready(function() {
$('#select-all-toggle-sunday').toggle(
function() {
$('.sunday').prop('checked', true);
},
function() {
$('.sunday').prop('checked', false);
}
);
});
</script>
任何幫助將不勝感激。
謝謝,
你不需要聲明document.ready每次你有一個新的切換。只要一次就好。 – tymeJV 2013-03-20 17:06:04