简体   繁体   English

在单选按钮检查上显示div

[英]Show div on radio button check

I would like to hide a div until the leased radio button is selected. 我想隐藏div,直到选择租用的单选按钮。 This div contains input fields only relative to the leased radio selection, so hiding them when the owned radio button is selected is preferred. 此div包含仅相对于租用无线电选择的输入字段,因此在选择拥有的单选按钮时隐藏它们是首选。 However, the code I have is not working. 但是,我的代码不起作用。

HTML HTML

<div id="surv_radio4">
    <p>
        Merchant Site Property is
    </p>
    <input type="radio" id="owned" value="owned" name="merchant_property"/>
    <label for="owned">Owned</label>
    <input type="radio" id="leased" value="leased" name="merchant_property"/>
    <label for="leased">Leased</label>
</div>
<div id="surv_5">
    <label for="landlord_name" class="test">Landlord Name</label>
    <input type="text" id="landlord_name" placeholder="Landlord Name"/>
    <label for="landlord_phone">Phone Number</label>
    <input type="text" id="landlord_phone" placeholder="XXX-XXX-XXXX"/>
</div>

CSS CSS

#surv_5 {
    display: none;
}

Javascript 使用Javascript

<script>
$(document).ready.(function() {
    $("input[name$='merchant_property']").click(function() {
        var value = $(this).val();
        if (value == 'leased') {
            $("#surv_5").show();
        } else if (value == 'owned') {
            $("#surv_5").hide();
        }
    });
});
</script>

Your document.ready function has a syntax error (extra period): 您的document.ready函数有语法错误(额外句点):

$(document).ready(function () {

http://jsfiddle.net/isherwood/tW3D5/ http://jsfiddle.net/isherwood/tW3D5/

Try this: 尝试这个:

$("input[name$='merchant_property']").change(function () {
    var value = $(this).val();    
    if (value == 'leased') {        
        $("#surv_5").show();
    } else {
        $("#surv_5").hide();
    }
});

Fiddle here. 在这里小提琴

On your original code, you also had an error on your else statement.. See fiddle here 在原始代码中,你的else语句也有错误。 请参阅此处的小提琴

Relevant bits below: 相关位如下:

if (value == 'leased') {
  $("#surv_5").show();
} else if(value == 'owned'){
  $("#surv_5").hide();
}

UPDATE UPDATE

Too late, looks like @Hiral has an answer for you.... 太晚了,看起来@Hiral有你的答案....

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

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