【问题标题】:popup Div td get value using Jquery弹出 Div td 使用 Jquery 获取值
【发布时间】:2018-05-31 11:24:56
【问题描述】:

下面是我试图在弹出窗口中显示的 div。我如何从弹出窗口中获取 td 值。尝试调用 popupClick() 时。它返回未定义。我附上了下面的代码。提前感谢您的帮助。

function btnSmartResult() {
            $.ajax({
                dataType: "json",
                url: "/Rule/SmartResultExecution",
                //datatype: "text",
                type: "POST",
                success: function (data) {
                    $('#smartresultTable tbody').empty();


                    $.each(JSON.parse(data), function (index, jsonResult) {
                        console.log(jsonResult.CurrentClaimIPID);
                        var rows = "<tr>" + "<td class='smartresultId'  onclick='popupClick();'><a href='#'>" + jsonResult.ClaimSummaryId + "</a></td>" + "<td>" + jsonResult.PatientName + "</td>" + "<td>" + jsonResult.PayorName + "</td>"
                            + "<td>" + jsonResult.ClientDemographicMasterID + "</td>" + "<td>" + jsonResult.AmountPaid + "</td>" + "</tr>";
                        $('#smartresultTable tbody').append(rows);
                    });
                var modal = document.getElementById('ruleSmartResultPopup');
                modal.style.display = "block";
            },
            error: function (data) { }
        });
    }



 function popupClick() {

        var obj = { claimSummaryID: parseInt($(this).closest("tr").find("td").eq(0).html()) };
        alert($(parseInt($(this).closest("tr").find("td").eq(0).html())));
    }
<div class="modal1-body" style="height:400px;overflow-y:auto;">
                <br />
                <div class="col-md-12 container-fluid">
                    <table id="smartresultTable" class="table table-striped table-bordered smartresultClass">
                        <thead style="text-align:center;background-color:cadetblue;color:white;">
                            <tr>
                                <td>ClaimSummaryID</td>
                                <td>PatientName</td>
                                <td>PayorName</td>
                                <td>ProviderName</td>
                                <td>TotalPaid</td>
                            </tr>
                        </thead>
                        <tbody style="text-align:center;"></tbody>
                    </table>
                </div>
            </div>

【问题讨论】:

  • 使用 createElement 为从 ajax 调用返回的数据创建元素,然后使用 .onclick = function () {} 将 td 链接到 click 事件
  • 请发布你的json数据。

标签: jquery html-table popupwindow trygetvalue


【解决方案1】:

试试这个

function btnSmartResult() {
            $.ajax({
                dataType: "json",
                url: "/Rule/SmartResultExecution",
                //datatype: "text",
                type: "POST",
                success: function (data) {
                    $('#smartresultTable tbody').empty();

                    $.each(JSON.parse(data), function (index, jsonResult) {
                        console.log(jsonResult.CurrentClaimIPID);
                        var rows = "<tr>" +
                        "<td class='smartresultId' id='" + jsonResult.ClaimSummaryId + "' onclick='popupClick(this.id);'><a href='#'>" + jsonResult.ClaimSummaryId + "</a></td>" +
                        "<td>" + jsonResult.PatientName + "</td>" +
                        "<td>" + jsonResult.PayorName + "</td>"
                        +
                        "<td>" + jsonResult.ClientDemographicMasterID + "</td>" +
                        "<td>" + jsonResult.AmountPaid + "</td>" +
                    "</tr>";
                        $('#smartresultTable tbody').append(rows);
                    });
                    var modal = document.getElementById('ruleSmartResultPopup');
                    modal.style.display = "block";
                },
                error: function (data) { }
            });
        }



        function popupClick(value) {
            alert(value);
        }

【讨论】:

    【解决方案2】:

    您应该使用.text() 而不是.html()

    您的代码将是:

    function popupClick() {
    
            var obj = { claimSummaryID: parseInt($(this).closest("tr").find("td").eq(0).html()) };
            alert($(parseInt($(this).closest("tr").find("td").eq(0).text()))); //<--Changed .html() to .text()
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-03
      • 1970-01-01
      • 2015-08-16
      • 2014-07-30
      • 2011-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多