这是我表格的一部分:
<label for="User">Select your account type:</label>
<select name="usertype" for="usertype" id="usertype" required>
<option value="1">Employee</option>
<option value="2">Manager</option>
</select>
<label for="User">Select the company you work for:</label>
<select name="company" for="company" id="company" required>
<?php
include ('processors/generate-company-list.php');
?>
<option value="NULL">I'll create my own company later</option>";
</select>
如果他们选择在表格中提前担任经理,我只希望<option value="NULL">I'll create my own company later</option>
可用。这可能吗?
答案 0 :(得分:0)
<script type="text/javascript">
function check(){
var usertype=document.getElementById("usertype").value;
if(usertype==2){
document.getElementById("company").selectedIndex = "0";
document.getElementById("company").disabled=true;
}else{
document.getElementById("company").disabled=false;
}
}
</script>
<label for="User">Select your account type:</label>
<select name="usertype" for="usertype" id="usertype" required onchange='check();'>
<option value="1">Employee</option>
<option value="2">Manager</option>
</select>
<label for="User">Select the company you work for:</label>
<select name="company" for="company" id="company" required>
<?php
include ('processors/generate-company-list.php');
?>
<option value="NULL">I'll create my own company later</option>";
<option value="1"> listitem1 </option>";
<option value="1"> listitem2</option>";
</select>
每当选择管理器并禁用第二个选择框时,我使用javascript函数选择0索引。