我有一個具有不同權限的用戶下拉菜單。用戶的不同權限是查看,編輯或刪除。從下拉菜單中選擇用戶時,複選框應根據其擁有的權限進行更新。我試過使用.prop()和.attr()無濟於事。 http://jsfiddle.net/DWM4r/選擇一個選項來檢查/取消選中複選框不起作用?
HTML
<select class='select210'>
<option class='user1'>[email protected]</option>
<option class='user2'>[email protected]</option>
<option class='user3'>[email protected]</option>
</select>
<input type='checkbox' checked class='viewChk' />View
<input type='checkbox' checked class='editChk' />Edit
<input type='checkbox' checked class='delChk' />Delete
jQuery的
$('.user3').click(function() {
$('.viewChk').attr('checked', true);
$('.editChk').attr('checked', false);
$('.delChk').attr('checked', false);
});
$('.user2').click(function() {
$('.viewChk').prop('checked', true);
$('.editChk').prop('checked', true);
$('.delChk').prop('checked', false);
});
$('.user1').click(function() {
$('.viewChk').prop('checked', true);
$('.editChk').prop('checked', true);
$('.delChk').prop('checked', true);
});