It's as easy as:
$('#UseUsername').change(function(){
if($(this).is(':checked')){
$('#div').show();
} else {
$('#div').hide();
}
});
Additionally, you could fire this event when the page loads, so the div will disappear if the checkbox isn't checked.
// Show the div only if the checkbox is checked
function toggleDiv(){
if($(this).is(':checked')){
$('#div').show();
} else {
$('#div').hide();
}
}
$(document).onload(function(){
// Set change event to hide/show the div
$('#UseUsername')
.change(toggleDiv)
.trigger('change');
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…