我喜欢"地区"除非用户选择" Player"否则表格将变灰。从第一个" Type"形成。这就是我所拥有的
<form name="form1" method="post" action="submitform.php">
Search for:<br>
<input type="text" value="" name="username">
<select name="Type">
<option value="">Select Type:</option>
<option value="Ch">Champion</option>
<option value="Pl">Player</option>
<option value="It">Item</option></select>
<select name="Region">
<option value="">Select Region:</option>
<option value="br">BR</option>
<option value="eune">EUNE</option>
<option value="euw">EUW</option>
<option value="lan">LAN</option>
<option value="les">LES</option>
<option value="na">NA</option>
<option value="oce">OCE</option>
<option value="ru">RU</option>
<option value="tr">TR</option>
<option value="kr">KR</option></select>
你怎么能这样做?
答案 0 :(得分:0)
将ID添加到您的元素中。 (这将使编码更容易。)
将Region select元素设置为最初禁用。
为Type添加单击处理程序,以根据所选的Type值重置Region项的disabled属性。
答案 1 :(得分:0)
HTML:
<form name="form1" method="post" action="submitform.php">
Search for:<br>
<input type="text" value="" name="username">
<select name="Type" id="type">
<option value="">Select Type:</option>
<option value="Ch">Champion</option>
<option value="Pl">Player</option>
<option value="It">Item</option></select>
<select name="Region" id="region" disabled>
<option value="">Select Region:</option>
<option value="br">BR</option>
<option value="eune">EUNE</option>
<option value="euw">EUW</option>
<option value="lan">LAN</option>
<option value="les">LES</option>
<option value="na">NA</option>
<option value="oce">OCE</option>
<option value="ru">RU</option>
<option value="tr">TR</option>
<option value="kr">KR</option></select>
使用Javascript:
document.getElementById("type").onchange = function() {
var type = document.getElementById("type");
var typeSelected = type.options[type.selectedIndex].text;
if(typeSelected == "Player") {
document.getElementById("region").disabled = false;
} else {
document.getElementById("region").disabled = true;
}
}