【问题标题】:CheckBox was not invoked未调用 CheckBox
【发布时间】:2014-04-10 08:54:00
【问题描述】:

我有我想要的复选框,如果它是真的显示下一个字段(这里是上传文件),当我点击它时没有任何反应,即视图没有刷新,知道如何解决吗?由于我对 Java 脚本很陌生,所以我可能会错过一些东西

<script type="text/javascript">
                $(function () {

                    $("#Visible").change(function () {
                        var checked = $(this).attr("checked");
                        if (checked) {
                            $("#File").show();
                        }
                        else {
                            $("#File").hide();
                         }
                    });
                });
            </script>

    <div class="form-group">
        @Html.LabelFor(model => model.Visible, new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Visible)
            @Html.ValidationMessageFor(model => model.Visible)
        </div>
    </div>


        <div class="form-group">

            @Html.LabelFor(model => model.File, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <input type="file" />
            </div>
        </div>

【问题讨论】:

  • 试试$(function () { $("#Visible").change(function () { $("#File").toggle(this.checked); }); });
  • 呈现的 HTML 标记是什么样的?
  • @Felix- 我应该如何找到它?

标签: javascript jquery asp.net asp.net-mvc razor


【解决方案1】:

你可以这样尝试:

$(function ()
 {     
      $("#Visible").change(function () 
      {         
        $("#File").toggle(this.checked);     
       }); 
 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    • 2016-05-11
    • 2019-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多