隐藏剃须刀引擎中的单选按钮

时间:2016-10-11 09:18:36

标签: javascript html razor

我想要隐藏一个单选按钮。我这样试试:

  @if (GetBoolean("bdCanOrderOnAccount"))
                                            {
                                                <div class="control-group">
                                                    <input type="radio" value="PAY1" id="EcomCartPaymethodID_PAY1a" name="EcomCartPaymethodID" class="pull-left" @if (GetString("Ecom:Order.PaymentMethodID").Equals("PAY1")) { <text> checked="checked" </text>           }>
                                                    <label for="EcomCartPaymethodID_PAY1a" class="pull-left radio-label">@Translate("choosepaymentmethodebankaccount", "Betaal op rekening")</label>
                                                </div>
                                            }
                                        <!--<div class="control-group">
                                            <input type="radio" value="PAY2" id="EcomCartPaymethodID_PAY2a" name="EcomCartPaymethodID" class="pull-left" @if (GetString("Ecom:Order.PaymentMethodID").Equals("PAY2")) { <text> checked="checked" </text>          }>
                                            <label for="EcomCartPaymethodID_PAY2a" class="pull-left radio-label">@Translate("choosepaymentmethodeideal", "Betaal online via iDeal")</label>
                                        </div>-->


                                        <div class="control-group">
                                            <input type="radio" value="PAY3" id="EcomCartPaymethodID_PAY3a" name="EcomCartPaymethodID" class="pull-left" @if (GetString("Ecom:Order.PaymentMethodID").Equals("PAY3")) { <text> checked="checked" </text>           }>
                                            <label for="EcomCartPaymethodID_PAY3a" class="pull-left radio-label">@Translate("choosepaymentmethodepickup", "Betaal bij afhalen")</label>
                                        </div>
                                    </div>

                                </div>

                        <script>
                                            $(function () {                                                 
                                              var rbtn = document.getElementById('EcomCartPaymethodID_PAY3a');
                                              document.getElementById('EcomCartPaymethodID_PAY3a').style.visibility = 'hidden';

                                              });
                                            </script>

因此,如果我在脚本中发出警报(&#39; hoi&#39;),那么我会看到hoi消息。但单选按钮并未隐藏。

怎么可能?

谢谢

但如果我这样做:

<div class="hallo">
                                        <div class="control-group">
                                            <input type="radio" value="PAY3" id="EcomCartPaymethodID_PAY3a" name="EcomCartPaymethodID" class="pull-left" @if (GetString("Ecom:Order.PaymentMethodID").Equals("PAY3")) { <text> checked="hecked" </text>           }>
                                            <label for="EcomCartPaymethodID_PAY3a" class="pull-left radio-label">@Translate("choosepaymentmethodepickup", "betaal bij afhalen")</label>
                                        </div>
                              </div>

和此:

<script>
                                            $(function () {                                              
                                              document.document.getElementsByClassName('hallo').style.visibility = 'hidden';

                                              });
                                            </script>

它没有隐藏

1 个答案:

答案 0 :(得分:1)

而不是

 document.document.getElementsByClassName('hallo').style.visibility = 'hidden';

正确的语法应该是:

document.getElementsByClassName('hallo')[0].style.visibility = 'hidden';

首先,document.document毫无意义。我认为这是一个错字。

其次,getElementsByClassName返回匹配元素的数组,因此您必须在数组索引中保存的各个元素上设置样式,而不是在数组本身上设置样式。对于这个例子,我把它设置在第一个元素([0])上,假设你只期望一个结果,但是如果你可能有多个结果,你需要循环遍历数组并对所有结果进行赋值他们。