当文件上载控件在按钮单击时没有任何文件时显示消息

时间:2016-10-12 07:58:36

标签: javascript jquery html file-upload

我的页面上有一个文件上传控件,我想限制只接受.csv文件,并在尝试上传任何其他文件的情况下抛出消息。此外,它应该在没有选择文件时单击上传按钮时抛出消息。

Html -

node_id

Javascript -

<div class="panel panel-primary">
    <div class="panel-heading">00</div>
    <div class="panel-body">
        <div class="field_row">
            <input type="file" accept=".csv" id="fileUpload" name="fileUpload1" />
        </div>
        <br />
        <div class="field_row">
            <div class="col-lg-12">
                <div class="form-group">
                    <center><div class="col-lg-3"><div class="input-append" id="filterDev" style="visibility: hidden">
                        <input name="search" id="inputFilter" placeholder="Enter ID to filter" />
                        <input type="button" value="Filter" id="filter" class="btn btn-primary" />
                    </div></div></center>
                    <div class="col-lg-6"></div>
                    <input type="button" id="upload" value="Upload" class="btn btn-primary" />
                    <input type="button" id="cancel" value="Cancel/Save" style="visibility: hidden" class="btn btn-primary" />
                    <input type="button" id="process" value="Process" style="visibility: hidden" class="btn btn-primary" />
                </div>
            </div>

            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default" style="align-self: center">
                        <div class="panel-body" style=" max-height:600px; min-height: 400px; overflow-y: scroll;">

                            <div class="row">
                                <div class="col-sm-12" id="dvCSV">
                                    <table id="my-table">
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <p id="download" style="color: cornflowerblue; visibility: hidden"><strong>Please click the below links to download the processed file..</strong></p>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="col-sm-3">
                    <p id="File1" style="color: cornflowerblue; text-decoration: underline; visibility: hidden"><a href="Files/CommitteeMembers.xlsx">File1 Download</a></p>
                </div>
                <div class="col-sm-3">
                    <p id="File2" style="color: cornflowerblue; text-decoration: underline; visibility: hidden"><a href="Files/GSD_Offering_Completion.csv">File2 Download</a></p>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

<script type="text/javascript">

    $("#cancel").on("click", function () {
        $('input:checked').each(function () {
            $(this).closest("tr").remove();
        });
    });


    $(function () {
        $("#process").bind("click", function () {

            document.getElementById("File1").style.visibility = "visible";
            document.getElementById("File2").style.visibility = "visible";
            document.getElementById("download").style.visibility = "visible";

        });

    });

    $("#filter").click(function () {
        ids = $("#inputFilter").val();
        if (ids != "") {
            idsArray = ids.split(",");
            $("#my-table tr:gt(0)").hide();
            $.each(idsArray, function (i, v) {
                $("#my-table tr[data-id=" + v + "]").show();
            })
        } else {
            $("#my-table tr").show();
        }
    });


    /*  $("#File1").click(function () {
          window.location = "Files/CommitteeMembers.xlsx";
      });
      $("#File1").click(function () {
          window.location = "Files/GSD_Offering_Completion.xlsx";
      });*/

</script>

如何实施?

0 个答案:

没有答案