Jquery 如何在下一页中追加数据<;李>;
我想在单击时将数据附加到最近的li上…我尝试了下一步,父级,最近,查找,什么都没有 这是我的JSFIDLE 我的jquery:Jquery 如何在下一页中追加数据<;李>;,jquery,html,Jquery,Html,我想在单击时将数据附加到最近的li上…我尝试了下一步,父级,最近,查找,什么都没有 这是我的JSFIDLE 我的jquery: $(document).ready(function(){ $(document).on('click', '.btnMoreInfo', function(){ $(this).closest(".test").next('.infoCatcher').append('<div class="moreInfo info">More C
$(document).ready(function(){
$(document).on('click', '.btnMoreInfo', function(){
$(this).closest(".test").next('.infoCatcher').append('<div class="moreInfo info">More Content..' + '</div>');
});
});
$(文档).ready(函数(){
$(文档).on('单击','.btnMoreInfo',函数(){
$(this).test(“.test”).next('.infoCatcher').append('More Content..'+'');
});
});
它不起作用。我可以知道为什么以及如何修复它吗?谢谢另一种方法是使用
儿童
和最近的
方法
$(document).ready(function(){
$(document).on('click', '.btnMoreInfo', function(){
$(this).closest("li").next().children('.infoCatcher').append('<div class="moreInfo info">More Content..' + '</div>');
});
});
$(文档).ready(函数(){
$(文档).on('单击','.btnMoreInfo',函数(){
$(this).closest(“li”).next().children('.infoCatcher').append('More Content..'+');
});
});
另一种方法是使用子类
和最接近的
方法
$(document).ready(function(){
$(document).on('click', '.btnMoreInfo', function(){
$(this).closest("li").next().children('.infoCatcher').append('<div class="moreInfo info">More Content..' + '</div>');
});
});
$(文档).ready(函数(){
$(文档).on('单击','.btnMoreInfo',函数(){
$(this).closest(“li”).next().children('.infoCatcher').append('More Content..'+');
});
});
使用closest()
只遍历三个DOM,因为.test
是您按钮的父级的兄弟,您没有找到任何内容
你需要像这样的东西:
$(this).parent().next().find('.infoCatcher').append('<div class="moreInfo info">More Content..' + '</div>');
$(this.parent().next().find('.infoCatcher').append('More Content..'+');
这将是:
实际按钮$(此)
到li父级.parent()
将标记上的下一个li作为.test的目标.next()
并在div infoCatcher上追加.find('.infoCatcher')
closest()
只遍历三个DOM,因为.test
是您按钮的父级的兄弟,您没有找到任何内容
你需要像这样的东西:
$(this).parent().next().find('.infoCatcher').append('<div class="moreInfo info">More Content..' + '</div>');
$(this.parent().next().find('.infoCatcher').append('More Content..'+');
这将是:
实际按钮$(此)
到li父级.parent()
将标记上的下一个li作为.test的目标.next()
并在div infoCatcher上追加.find('.infoCatcher')
下面是一个纯Javascript示例,说明如何针对最近的
li
:
还有这个片段:
var closestLi=document.body.firstElementChild.firstElementChild;
var content=document.createTextNode(“此处的内容”);
closestLi.appendChild(内容)代码>
-
更多
-
-
更多
-
-
更多
-
-
更多
-
下面是一个纯Javascript示例,说明如何瞄准最接近的li
:
还有这个片段:
var closestLi=document.body.firstElementChild.firstElementChild;
var content=document.createTextNode(“此处的内容”);
closestLi.appendChild(内容)代码>
-
更多
-
-
更多
-
-
更多
-
-
更多
-
最近的li将是按钮的父级。。。你是说最接近的李级考试吗?我不知道你想在这里取得什么成绩。你只是想得到更多的信息,就像小提琴?谢谢@DaniP!。。。把这当作一个有效的答案!最近的li将是按钮的父级。。。你是说最接近的李级考试吗?我不知道你想在这里取得什么成绩。你只是想得到更多的信息,就像小提琴?谢谢@DaniP!。。。把这当作一个有效的答案!