我有這個問題:在我的表單中有4個下拉列表,當選擇1st(category1)或2nd(software1)下拉列表時,第3個(category2)和第4(軟件2)必須禁用。如果選擇1st或2nr,則禁用第3個,第4個下拉列表
對於這個問題,我覺得在這disable-second-dropdown-if-the-first-is-not-selected腳本,但我不相信修改此:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
category1
<select name='cat1'>
<option value='0'>Select one</option>
<option value='1'>little</option>
<option value='2'>good</option>
</select>
software1
<select name='soft1'>
<option value=''>Select one</option>
<option value='W'>Word</option>
<option value='E'>Excel</option>
<option value='PP'>Power Point</option>
</select>
<br />
category2
<select name='cat2'>
<option value='0'>Select one</option>
<option value='1'>little</option>
<option value='2'>good</option>
</select>
software2
<select name='soft2'>
<option value=''>Select one</option>
<option value='W'>Word</option>
<option value='E'>Excel</option>
<option value='PP'>Power Point</option>
</select>
<script type="text/javascript">
var setEnabled = function(e) {
var name = this.name.replace(/1/, '2'); //get name for second drop down
$('select[name=' + name + ']')
.prop('disabled', 0 === this.selectedIndex) // disable if selected option is first one
};
$(function() {
$('select[name=cat1], select[name=soft1]')
.on('change', setEnabled)
.trigger('change'); // trigger on page load
});
</script>
如何修改呢?
感謝
是在底部或右側的第三和第四下拉菜單?在底部的那些被禁用 – depperm
當你禁用它們時,你是否也想將它們設置爲「選擇一個」? –
@ depperm:我已編輯文章 – Frankie