Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery更改h5元素中的文本_Javascript_Jquery - Fatal编程技术网

Javascript 使用jQuery更改h5元素中的文本

Javascript 使用jQuery更改h5元素中的文本,javascript,jquery,Javascript,Jquery,我试图添加一个元素来显示页码/总页数,如下所示: 页码:1/6 这就是我所拥有的,我用jQuery绘制了一个完整的HTML模板,因为代码太多了,所以这里有一个我所做的示例(此代码用于第1/1页): var html = ""; //Here I draw my html code html += '<td>'; html += '<h5 id="p1" class="text-right">Pag: ' + div + '/' + total + '</h5>

我试图添加一个元素来显示页码/总页数,如下所示:

页码:1/6

这就是我所拥有的,我用jQuery绘制了一个完整的HTML模板,因为代码太多了,所以这里有一个我所做的示例(此代码用于第1/1页)

var html = ""; //Here I draw my html code
html += '<td>';
html += '<h5 id="p1" class="text-right">Pag: ' + div + '/' + total + '</h5>';'
html += '</td>';
A lot of code.... and finally...

//I have 4 div (a total of 4 pages) so this is the reason of why I'm doing this:
var p = "div" + div.toString();
$('#' + p).html(html); //The final result is: #div1, #div2... etc
var pag = "Pag: 1/2";
$('#p1').text(pag);
var pag1 = "Pag: 1/3";
var pag2 = "Pag: 2/3";
$('#p1').text(pag1);
$('#p2').text(pag2);
有了这个,我将h5从第1页改为第1页(现在1/1是1/2)

在这一部分,一切都没问题,但是当我尝试对第3页和第4页做同样的事情时,文本没有改变,所以我的问题是什么可能是问题?因为我在第1页和第2页上做了完全相同的事情,但在第3页和第4页上没有,但是我在第3页上做的是:

var html = ""; //Here I draw my html code
html += '<td>';
html += '<h5 id="p1" class="text-right">Pag: ' + div + '/' + total + '</h5>';'
html += '</td>';
A lot of code.... and finally...

//I have 4 div (a total of 4 pages) so this is the reason of why I'm doing this:
var p = "div" + div.toString();
$('#' + p).html(html); //The final result is: #div1, #div2... etc
var pag = "Pag: 1/2";
$('#p1').text(pag);
var pag1 = "Pag: 1/3";
var pag2 = "Pag: 2/3";
$('#p1').text(pag1);
$('#p2').text(pag2);
正如您所看到的,它应该可以工作,下面是我绘制html的函数:

$('#go').click(function () {
    div++;
    total++;

    if (div == 1)
        drawPage1(); //div and total = 1, h5 id="p1" Pag: 1/1
    if (div == 2)
        drawPage2(); //div and total = 2, h5 id="p2" Pag: 2/2
    if (div == 3)
        drawPage3(); ////div and total = 3, h5 id="p3" Pag: 3/3
});

为什么这在第1页和第2页中有效,而在第3页和第4页中无效,这可能是什么问题?提前感谢。

在执行绘制第3页和第4页的函数之前,某些函数破坏了我的代码,解决方案。。。阅读控制台试图告诉我的内容。

控制台错误?我有一个错误,但不是关于我的函数,但可能这个错误在某个时候破坏了我的所有js文件,让我尝试解决它,看看是否解决了这个问题是,在执行函数drawPage3()之前,某个函数破坏了我的代码,那么我现在能做什么?删除问题?回答我所做的事情,并像正确答案或什么一样标记?您可以添加一个答案并将其标记为正确,以便其他人可以从中学习。