【问题标题】:Enable file upload when check box is true复选框为真时启用文件上传
【发布时间】:2014-05-24 00:34:21
【问题描述】:

我已经勾选了我想要的复选框,如果 show=true(show = Boolean type)启用文件上传,所以默认情况下该复选框未选中并且文件上传被禁用,我该怎么做? 当您单击启用/禁用不起作用时,我尝试使用以下无法正常工作的代码。

$(function () {
    $("#show").change(function () {
       $("#fileUpload").toggle(this.checked).prop("disabled", false);
    });
});
$("#fileUpload").toggle(this.checked).prop("disabled", true);




<div class="form-group">
    @Html.LabelFor(model => model.show, new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.EditorFor(model => model.show)
        @Html.ValidationMessageFor(model => model.show)
    </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" id="fileUpload"/>
        </div>
    </div>

【问题讨论】:

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


    【解决方案1】:

    为什么在勾选复选框之前不使用隐藏文件上传?

    $(document).ready(function(){
        $('#uploads').hide();
        $('#enable_uploads').change(function(){
            $('#uploads').toggle()
        });
    });
    

    喜欢这个小提琴:http://jsfiddle.net/E3PHP/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-12
      相关资源
      最近更新 更多