Javascript/Html如何使用下拉框禁用下拉框

Javascript/Html如何使用下拉框禁用下拉框,javascript,html,Javascript,Html,只是想知道有谁能给我一个例子,当一个下拉框中的一个选项没有被选中时,如何禁用下拉框 e、 g 状态(仅限澳大利亚): 新南威尔士州 北领地 昆士兰 国家: 澳大利亚 巴西 中国 所选函数() 如果(document.selectCountry.checked) { document.getElementById(“selectCountry.Australia”).disabled=false; } 其他的 { document.getElementById(“selectCount

只是想知道有谁能给我一个例子,当一个下拉框中的一个选项没有被选中时,如何禁用下拉框

e、 g

状态(仅限澳大利亚):
新南威尔士州
北领地
昆士兰
国家:
澳大利亚
巴西
中国
所选函数()
如果(document.selectCountry.checked)
{
document.getElementById(“selectCountry.Australia”).disabled=false;
}   
其他的
{   
document.getElementById(“selectCountry.Australia”).disabled=true;
}
我希望使用JAVASCRIPT禁用状态下拉列表,除非选择澳大利亚。。我能得到一些帮助吗


我对整个Javascript编码还是有点陌生,如果我的代码不好,我很抱歉,但我希望你能理解我的问题

你需要像这样修复你的js代码

function selected(){
 if(document.getElementById("selectCountry").value == "Australia") {
   document.getElementById("selectState").removeAttribute("disabled");
 }   
 else {   
   document.getElementById("selectState").setAttribute("disabled","disabled");
 }
}
下面是上面代码的示例


更新为在页面加载时调用函数,如果默认国家/地区不是“Australia”

我尝试过这样做,但没有成功?我明白密码,但是。。是的,我可能需要在select标记中添加一些东西来调用该函数吗?或者?是的,您必须在国家/地区selectbox的“onchange”事件中调用您的函数。您还可以在页面加载时调用此函数来设置默认值。其余部分将由“onchange”函数调用处理检查更新的fiddle,以便在页面加载时调用该函数。非常感谢!感谢您抽出时间来帮助我们这些新手!
function selected(){
 if(document.getElementById("selectCountry").value == "Australia") {
   document.getElementById("selectState").removeAttribute("disabled");
 }   
 else {   
   document.getElementById("selectState").setAttribute("disabled","disabled");
 }
}