如何在JavaScript中动态更改jQuery dataTable页面编号?

时间:2018-02-15 12:27:29

标签: javascript jquery datatable datatables

我有这个代码,它是根据按钮点击从服务中获取数据。单击上一个或下一个按钮时我想要的是什么,我想更改dataTable底部的页面编号。

$('.paginate_button.previous', this.api().table().container())
                            .on('click', function(){
                               // alert("Doruk");
                                if(pageNumber > 1) {
                                    $.ajax({
                                        url: "http://192.168.1.171:8080/LogWS/rest/v1/logs/normalized-logs-paged?pageNumber=" + pageNumber-- + "&&pageCount=10",
                                        type: "post",
                                        dataType: "json",
                                        traditional: true,
                                        contentType: "application/json; charset=utf-8",
                                        processData: false,
                                        headers: {
                                            Authorization: "Bearer " + localStorage.getItem("globalAuthenticationKey")
                                        },
                                        data:
                                            JSON.stringify(hostAddresses)

                                        ,

                                        success: function (response) {

                                            var Table = document.getElementById("applicationviewTableID");
                                            Table.innerHTML = "";
                                            for (var i = 0; i < response.logData.length; i++) {
                                                var trHTML = '';
                                                // var trHTML2 = '';
                                                trHTML += '<tr><td>' + response.logData[i].ip + '</td><td>' + response.logData[i].application + '</td><td>' + "" + '</td>';
                                                $('#applicationviewTableID').append(trHTML);
                                                /*  trHTML2 += '<tr><td>' + response.logData[i].ip + '</td><td>' + response.logData[i].application + '</td><td>' + response.logData[i].operation + '</td><td>' + response.logData[i].entityType + '</td><td>' + response.logData[i].entity + '</td><td>' + response.logData[i].time + '</td>'
                                                  $('#DetailedApplicationsMalwareTableBodyID').append(trHTML2);*/
                                            }



                                            console.log( $('.paginate_button.active')[0]);


                                        },

下面的代码显示了我想在控制台中更改的html代码段。

console.log( $('.paginate_button.active')[0]);

显示

<li class="paginate_button active"><a href="#" aria-controls="ApplicationVİEWTABLE" data-dt-idx="1" tabindex="0">1</a></li>

我想在“a”标签内改变“1”

我该怎么做

1 个答案:

答案 0 :(得分:0)

您还必须选择内部a标签。 然后你可以得到这样的文字:

$('.paginate_button.active a').text();

或编辑如下:

$('.paginate_button.active a').text("2")