简体   繁体   English

Javascript单选按钮显示隐藏

[英]Javascript Radio Button Show hide

Trying to get the text field please specify to show and hide.尝试获取文本字段please specify显示和隐藏。 Here's my code.这是我的代码。

` `

There is text field missing in code, so based on Trying to get the text field please specify to show and hide代码中缺少文本字段,因此基于Trying to get the text field please specify to show and hide

HTML text-field HTML 文本字段

<label class="option" for="edit-submitted-distributions-fieldset-1-fund-distribution-select-1">other (please specify)</label>
<input id="edit-submitted-distributions-fieldset-1-widg-donation1otherdescription" type="text">

and JS code will be和 JS 代码将是

$(document).ready(function() {
    $("#edit-submitted-distributions-fieldset-1-widg-donation1otherdescription").hide();
    $("#edit-submitted-distributions-fieldset-1-fund-distribution-select-1").click(function () {
         if ($(this).val() === "0000~0000") {
             $("#edit-submitted-distributions-fieldset-1-widg-donation1otherdescription").show();
         } else {
             $("#edit-submitted-distributions-fieldset-1-widg-donation1otherdescription").hide();

         }
    });
});

Fiddle小提琴

In JS code you are binding the label id="edit-submitted-distributions-fieldset-1-fund-distribution-select"在 JS 代码中,您绑定label id="edit-submitted-distributions-fieldset-1-fund-distribution-select"

But to hide and show the text field if click on radio button like you said in question title, you have to bind the click function with radio button id id="edit-submitted-distributions-fieldset-1-fund-distribution-select-1"但是,如果单击问题标题中所说的单选按钮,则要隐藏和显示文本字段,您必须将单击功能与单选按钮 id id="edit-submitted-distributions-fieldset-1-fund-distribution-select-1"绑定id="edit-submitted-distributions-fieldset-1-fund-distribution-select-1"

and this $("#edit-submitted-distributions-fieldset-1-widg-donation1otherdescription").prop("disabled", false);而这个$("#edit-submitted-distributions-fieldset-1-widg-donation1otherdescription").prop("disabled", false); only makes the input not disable, it has nothing to do with hide / show the input.只使输入不被禁用,它与隐藏/显示输入无关。

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

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