猿问

按钮不响应 HTML 表导出到 Excel - jQuery

我正在尝试将 html 表导出到 excel。当我使用此代码时,表会在加载表后立即尝试导出:


<script>


    $("#excel").table2excel({

        exclude: ".excludeThisClass",

        name: "Kontrakt",

        filename: "Kontrakt.xls"

    });

</script>

但是当我尝试使用 btn 执行导出时它没有响应:


<script type="text/javascript">

    $(function () {

        $("#btnExport").click(function () {

          $("#excel").table2excel({

            exclude: ".excludeThisClass",

            name: "Kontrakt",

            filename: "Kontrakt.xls"

            });

        });

    });

</script>


我需要帮助解决这个问题。


编辑:更多代码


<input type="button" id="btnExport" value="Export" />

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script src="~/table2excel.js" type="text/javascript"></script>


喵喔喔
浏览 153回答 1
1回答

元芳怎么了

我通过在表单中添加一个输入类型复选框然后查询是否设置了该复选框来解决它。<td><input type="checkbox" name="ruta" /></td>@if (ruta == "on"){&nbsp; &nbsp;<script>&nbsp; &nbsp; &nbsp; $("#excel").table2excel({&nbsp; &nbsp; &nbsp; exclude: ".excludeThisClass",&nbsp; &nbsp; &nbsp; name: "Kontrakt",&nbsp; &nbsp; &nbsp; filename: "Kontrakt.xls"&nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; </script>}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答