【问题标题】:When Radio button checked, datetime picker does not show and checked false doesnt work当收音机按钮检查时,dateTimePicker不显示和检查false不起作用
【发布时间】:2016-03-13 04:36:20
【问题描述】:

我有两个单选按钮,立即交付和交付于。立即交付默认选中。如果客户在单击交货时间按钮时希望稍后交货,则必须显示日期选择器并且必须取消选中立即交货单选按钮。但这些不会发生。日期选择器未显示,并且立即交货单选未变为未选中状态。我的代码有什么问题?任何人都可以帮忙。谢谢。

下面你可以看到我的观点;

<div class="checkout-nameoncake-itemcontainer">
    <div class="checkout-nameoncake-name">
        <label class="label-checkout-deliverytime">Deliver Now(~ 45dk.)</label><input type="radio" id="DeliveryNowRadio" checked="checked" name="DeliveryNow" value=" " />
        <label class="label-checkout-deliverytime">Delivert at </label><input type="radio" id="DeliveryLaterRadio" name="RequestedDeliveryDate" value=" " />
    </div>
    <div class="checkout-nameoncake-details">
        <input type="date" name="name" class="datepicker" id="datepicker" style="margin: 17% 0 0 5%;border-radius: 7%;border: solid;border-width: thin;border-color: lightblue;display:none" value="" />
    </div>
</div>

你可以在下面看到我的 jquery。

<script>
    $(document).ready(function () {
        $("#DeliveryLaterRadio").click(function () {
            $("#DeliveryNowRadio").prop("checked", false);
            $(".datepicker").css("display", "inline-block");
        });

        $("#DeliveryNowRadio").click(function () {
            $("#DeliveryLaterRadio").prop("checked", false);
            $(".datepicker").css("display", "none");
        });
    });
</script>

【问题讨论】:

    标签: jquery radio-button checked


    【解决方案1】:

    我在 plunker 上试用了你的代码,它可以工作:

    https://plnkr.co/OJVF85JgJiZSghMtyUtf

    <!DOCTYPE html>
    <html>
    
      <head>
        <script data-require="jquery@2.2.0" data-semver="2.2.0" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
      </head>
    
      <body>
        <div class="checkout-nameoncake-itemcontainer">
          <div class="checkout-nameoncake-name">
            <label class="label-checkout-deliverytime">Deliver Now(~ 45dk.)</label>
            <input type="radio" id="DeliveryNowRadio" checked="checked" name="DeliveryNow" value=" " />
            <label class="label-checkout-deliverytime">Delivert at </label>
            <input type="radio" id="DeliveryLaterRadio" name="RequestedDeliveryDate" value=" " />
          </div>
          <div class="checkout-nameoncake-details">
            <input type="date" name="name" class="datepicker" id="datepicker" style="margin: 17% 0 0 5%;border-radius: 7%;border: solid;border-width: thin;border-color: lightblue;display:none" value="" />
          </div>
        </div>
        <script>
        $(document).ready(function () {
            $("#DeliveryLaterRadio").click(function () {
                $("#DeliveryNowRadio").prop("checked", false);
                $(".datepicker").css("display", "inline-block");
            });
    
            $("#DeliveryNowRadio").click(function () {
                $("#DeliveryLaterRadio").prop("checked", false);
                $(".datepicker").css("display", "none");
            });
        });
      </script>
      </body>
    
    
    
    </html>
    

    【讨论】:

    • 我不明白发生了什么,但它现在也适用于我。感谢您的宝贵时间。@raszpi
    • 太好了,很高兴为您提供帮助:]
    猜你喜欢
    • 2016-05-29
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    相关资源
    最近更新 更多