
[英]How to get clone of HTML, modify it, get HTML string without affecting DOM?
[英]How to delete a column and get html without affecting the dom in Jquery
我有一个 asp.net 应用程序。 我想通过网格视图 HTML 最后没有删除按钮,以使用 jquery 生成 pdf 而不会影响 DOM。 所以我需要得到没有最后一个和 td 的 gridview 的 html。 我将如何做到这一点?
<div id="container>
<asp:GridView ID="GridView1" CssClass = "Grid" runat="server" OnRowDeleting="OnRowDeleting" AutoGenerateColumns = "false" OnRowDataBound = "OnRowDataBound">
<Columns>
<asp:BoundField DataField="Item" HeaderText="Item" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
</Columns>
</asp:GridView>
</div>
<Button class="Print-Button" ID="btnExportPdf" data-val="PRT">Export to PDF</Button>
<script type="text/javascript">
$(function () {
$(document).on("click", ".Print-Button", function (e) {
var ItemHTML = $('#container').html();
// I have to remove the delete button (last column) and send to code behind to generate pdf
var dataVal = { value: ItemHTML };
$.ajax({
url: "webApplication1.aspx/GetURL",
contentType: "application/json; charset=utf-8",
type: "POST",
dataType: "json",
data: JSON.stringify(dataVal),
success: function (data) {
},
error: function (result) {
alert(result);
}
});
});
您可以执行以下操作
<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false" ClientIDMode="Static">
<Columns>
<asp:BoundField DataField="Item" HeaderText="Item" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:CommandField ShowDeleteButton="True" ButtonType="Button" ControlStyle-CssClass="hideonprint" />
</Columns>
</asp:GridView>
<button type="button" class="btn">Export to PDF</button>
<div id="box"></div>
<script type="text/javascript">
jQuery(function () {
jQuery('.btn').click(function (e) {
jQuery('.hideonprint').hide();
var gv = jQuery('#GridView1').html();
jQuery('.hideonprint').show();
jQuery('#box').html(gv);
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.