验证输入文件

时间:2021-07-12 21:00:43

标签: javascript asp.net validation input

你能检查一下我的代码吗?

你需要实现什么,当一个文件被选中时,存储一个按钮来清理输入文件,以便它可以被选中,

当输入文件为空时,清理输入的按钮不应该如果是可见的,原则上我的删除按钮是不可见的

Form.aspx 代码

<asp:TableRow>
            <asp:TableCell>
                <asp:Label ID="lblAtachhInvoice" Text="Attach Invoice " runat="server"></asp:Label>
            </asp:TableCell><asp:TableCell>
                <asp:FileUpload ID="fuInvoiceFile" runat="server" ClientIDMode="Static" />
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell>
            </asp:TableCell><asp:TableCell>
                <asp:LinkButton ID="btnDeleteFile" runat="server" Text=" Delete File " Visible="true" ClientIDMode="Static" />
            </asp:TableCell></asp:TableRow><asp:TableRow>

JavaScript 代码

<script type="text/javascript">

var btnDelete = document.getElementById('<%= btnDeleteFile.ClientID %>');
    var inputFile = document.getElementById('<%= fuInvoiceFile.ClientID %>');

    if (inputFile.value != '') {
       
        $('[id*=btnDeleteFile]').show();
    }
    else {
        $('[id*=btnDeleteFile]').hide();
    }

</script>

0 个答案:

没有答案
相关问题