简体   繁体   English

如果我选择其他国家,则不会显示该州

[英]The state does not reappear if I select another country

The state field should be a hidden if I select country Mauritius, which works. 如果我选择有效的国家/地区毛里求斯,则状态字段应为隐藏。 The problem is that after choosing Mauritius, if I choose another country, the state field does not reappear. 问题是选择毛里求斯后,如果我选择另一个国家,州域不会重新出现。

<input id="state" name="state" type="text" placeholder="Amsterdam"
       style="visibility:visible" onfocus="con()">
<label for="country" id="country">Country</label>
            <select name="country">
                <option value=""></option>
                <option value="AF">Afghanistan</option>
                <option value="AL">Albania</option>
                <option value="DZ">Algeria</option>
                <option value="MU">Mauritius</option>
                                    your country</select>

function con() {
    var z=document.forms["task2"]["country"].value;
    var z11 = document.getElementById("male");
    var z12 = document.getElementById("state");

    if(z=="MU")
    {
        document.getElementById('state').style.visibility = 'hidden';
        z11.focus();
        return false;
    } else if(z!="MU") {
    z12.focus();
    document.getElementById('state').style.visibility='visible';
    z12.focus();
    }
}

http://jsfiddle.net/Maslow/pXMdL/ http://jsfiddle.net/Maslow/pXMdL/

It needs to be onchange and there were other errors, like not listening to the select change. 它必须是onchange,并且还有其他错误,例如不听选择更改。 which is probably where your listener should have been in general. 大概是您的听众应该在的地方。 Also your sample didn't include the html for the form. 另外,您的示例中未包含表单的html。

"your country" was outside of any valid elements (inside <select> but not inside an <option></option> tag. “您的国家”在任何有效元素之外(在<select>但不在<option></option>标记内)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM