<script>
$('#Select_Font').attr('disabled', 'true');
$('#Enter_Text').attr('disabled', 'true');
$('.dropdownstyle').change(function(){
$(".dropdownstyle option:selected").text();
if($(this).attr('value').match(/Custom$/))
{
$('#Select_Font').attr('disabled', 'false');
$('#Enter_Text').attr('disabled', 'false');
} else if($(this).attr('value').match(/no Thanks$/))
{
$('#Select_Font').attr('disabled', 'true');
$('#Enter_Text').attr('disabled', 'true');
}
});
</script>
<table>
<tbody>
<tr>
<td>
<span>Select type</span>
</td>
<td>
<select class="dropdownstyle">
<option value="No Thanks">No Thanks</option>
<option value="Custom lid (200)">Custom lid (200)</option>
</select>
</td>
</tr>
<tr>
<td>
<span>Select font</span>
</td>
<td>
<select id="Select_Font">
<option value="Arial">Arial</option>
<option value="georgia">georgia</option>
</select>
</td>
</tr>
<tr>
<td>
<span>enter text</span>
</td>
<td>
<input type="text" id="Enter_Text">
</td>
</tr>
</tbody>
</table>
在上面的代碼最初我希望字體下拉和文本框禁用,但選擇自定義窗體第一個下拉我希望字體下拉和文本框啓用。 我不確定我要出錯的地方,所以應該做些什麼才能使它工作。如何啓用或禁用選擇其他下拉菜單上的下拉菜單或文本框?
這是正確的$(this).attr('value')。match(/ Custom $ /)或者其他方式是更好的檢查? – 2013-03-08 19:07:58
查看更新的答案與工作小提琴... – Anujith 2013-03-08 19:09:09
其工作謝謝... – 2013-03-08 19:18:20