有一個選擇下拉列表,其中一個選項最初禁用。我想要的是在單擊複選框時啓用該選項只有。不知道如何做到這一點的一個選項,而不是我啓用/禁用整個選擇下拉列表:(。單擊複選框時從選擇標記中啓用選項
<input type='checkbox' id='details' name='form_details<?php if ($form_details) echo ' checked'; ?> onchange='enableOption()';>
<select name='form_summarize_by' id='summarize_by'>
<?php
echo " <option value='0'>Orange</option>\n";
echo " <option value='1'" . (!$form_details ? "disabled='disabled'":"") . ">Pear</option>";
?>
<script type="text/javascript">
function enableOption(){
if(document.getElementById('details').checked == true)
{
document.getElementById('summarize_by').removeAttribute('disabled');
}
else
{
document.getElementById('summarize_by').setAttribute('disabled', 'disabled');
}
}
</script>
disabled屬性是布爾值,所以不應該給它賦值。即'<禁用選項/>'vs'
發佈呈現的HTML,而不是PHP。 – j08691