javascript - 如何调用Jquery数据表中的函数

标签 javascript jquery html

我有这些代码行。我想向某行添加功能。单击时它会运行另一个功能。但它无法识别函数声明。单击某行时如何调用函数?以及如何将参数发送到与该行关联的函数。

$(document).ready(function() {
      var restVul = function() {
        alert("tik");
      }

      $.ajax({
        url: "https://localhost:450/rest/products?pageNumber=1&pageCount=80",
        type: "POST",
        dataType: "json",
        headers: {
          'Content-Type': 'application/json'
        },
        traditional: true,
        contentType: "application/json; charset=utf-8",
        processData: false,
        data: JSON.stringify(hostAddresses),
        success: function(response) {
          console.log(response);
          for (var i = 0; i < response.length; i++) {
            var trHTML = '';
            for (var j = 0; j < response[i].Products.length; j++) {
              trHTML += '<tr class="clickable-row" data-href="index.html"><td>' + response[i].IP + '</td><td onclick="function () {alert();  }">' + response[i].Products[j].Product + '</td><td>' + response[i].Products[j].CVECount + '</td></tr>';
            }
            $('#ProductsTableBody').append(trHTML);
          }

          $('.js-exportable').DataTable({
            dom: 'Bfrtip',
            responsive: true,
            buttons: [
              'copy', 'csv', 'excel', 'pdf', 'print'
            ]
          });
        },
        error: function(xhr) {
          console.log("Hata Oluştu...");
        }
      })

最佳答案

在行中使用以下代码

columns: [
{"data": "xxx", "width": "10%","visible": false, "render": function (data, type, row, meta) {   }    },
]

在函数中使用以下代码在列上创建可点击的链接

if (type === 'display') {
        return $('<a>')
        .attr('href', ' ')
        .text(data)
        .wrap('<div></div>')
        .parent()
        .html();
     } else {
          return data;
     }

关于javascript - 如何调用Jquery数据表中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46768127/

相关文章:

javascript - 如何禁用表单按钮直到功能完全完成

javascript - 如何在javascript中将带有路线的谷歌地图转换为图像

javascript - Webpack 5 不显示图像

javascript - 如何在javascript中查找特定日期格式的日期差异?

html - 扩展模板不适用于 FOSUserBundle 电子邮件。交响乐2

python - 如何获取 Flask 请求 JSON 数据作为字典?

javascript - Jquery attr 不工作 Internet Explorer

javascript - php 生成 html 按钮来运行 javascript

html - 所有边框颜色不变(仅底部和右侧边框发生变化)

html - RegExp 搜索 HTML 标签内的文本