我有我的网站使用联系表,我使用的代码如下
<label> Your Name (required)
[text* your-name] </label>
<label> Your Email (required)
[email* your-email] </label>
<label> Your Country
[select country id:CountryDropDown first_as_label "Select" "United Kingdom" "United States"] </label>
<label id="UkStates"> State
[select state "London" "Scotland"] </label>
<label id="UsaStates"> State
[select state "San Francisco" "New York"] </label>
[submit "Send"]
<script language="javascript" type="text/javascript">
document.getElementById("UkStates").style.display = \'none\';
document.getElementById("CountryDropDown").addEventListener("change", displayTextField);
function displayTextField() {
var dropDownText = document.getElementById("CountryDropDown").value;
if (dropDownText == "United Kingdom") {
document.getElementById("UkStates").style.display = \'block\';
} else {
document.getElementById("UkStates").style.display = \'none\';
}
}
</script>
此代码仅在一种情况下工作。我的问题是如何使用JavaScript创建更多条件。
例如:“国家”字段也有“美国”,因此如果选择“美国”,则只显示美国。
若问题扩大到较大的范围,请原谅。谢谢