- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为一个网站制作一个评论系统,该系统通过 Ajax 请求获取评论并将它们添加到评论列表中。这工作正常,但它总是将它们添加到列表的底部。这是因为我正在使用 list.appendChild(item);
为此,我现在需要找到替代方案...
有没有办法添加一个<li>
另一个 <li>
下的元素我知道其中的 ID?
这是一个video包含当前行为
及其代码:
function loadcomments(id){
$.ajax({
url: '/ajax/getcomments/',
data: {
'identifier': '{{ identifier }}',
'id': id,
'begin': '0',
'end': '30',
},
dataType: 'json',
success: function (data) {
var json = JSON.parse(data.comments);
console.log(json);
makeUL(json);
function makeUL(array) {
list = document.getElementById('commentlist');
for(var i = 0; i < array.length; i++) {
if(!document.getElementById("comment-id-" + array[i].pk)){
var item = document.createElement('li');
item.className = "commentlistelement"
item.setAttribute('id',"comment-listitem-id-" + array[i].pk)
var maindiv = document.createElement('div')
maindiv.setAttribute('id',"comment-id-" + array[i].pk);
maindiv.className = "row comment";
maindiv.setAttribute("style","padding-left: "+3*array[i].fields.indent+"vw;");
maindiv.innerHTML = "<div class=\"col-md-1\">profile<br>pic</div><div class=\"col-md-9\"><small>"+ array[i].fields.user +" </small><small><button class=\"buttonlink\" onclick=\"reply("+ array[i].pk +")\">reply</button></small> <small><button class=\"buttonlink\" onclick=\"loadcomments("+ array[i].pk +")\">show more</button></small><br><p>" + array[i].fields.description + "</p></div>";
item.appendChild(maindiv);
list.appendChild(item);
}
}
return list;
}
}
});
};
最佳答案
您或许可以使用 Node 对象的 firstChild
和 insertBefore
方法:
https://developer.mozilla.org/en-US/docs/Web/API/Node/firstChild
https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
JQuery 也有一个 insert after 方法:
http://api.jquery.com/insertafter/
获取列表容器的第一个 child 。然后在它前面插入。
关于javascript - 在 unorderdlist 中的指定 listItem 下插入项目,而不是在底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48242972/
我正在尝试将对象 MyItem 的 ArrayList 从一个 Activity 传递到另一个 Activity 。据我了解,我需要在 MyItem 类中实现 Parcable。所以这就是我到目前为止
我正在使用 SimpleCursorAdapter 和 ListView 来显示加载器加载的一些数据。在 cursor 中,我有一个 int 从 0 到 3 的项目。 我希望此 int 等于 0-1
我正在开发一个菜单项,其代码在下面提供。我试图在单击时更改菜单项的样式。我已经应用了一个函数 clickHandler 来在选定和未选定状态之间切换。根据 menuItem 的状态,我想更改其样式。在
我有一个包含 ImgaeView 的 ListItem。我想在单击其图像或图标时删除 ListItem。这是我的 ListItemActivity。我将如何调用适配器的 remove 方法来删除
我的 ListItem 中有 3 个 RadioButtons 以及一些使用 CursorAdapter 的文本。当我单击 ListItem 中的任何 RadioButton 时,我需要获取 View
我是编码世界的新手。学习react和json。我正在研究三个链接在一起的不同面板。我想在第三个面板上显示 list 答案。 第一个面板: 显示:所有esn("4667","4668") onclick
我正在使用 Material UI 库,无法弄清楚是否有办法在一个列表项上发生 2 个不同的点击事件。 这基本上就是我所拥有的: insideAvatarFunction
在 ListView 中,如何随时将对象附加到已存在的 ListItem? (我知道我可以使用 AddItem 将对象附加到 ListItem,但是我需要在创建 ListItem 之后附加对象)。 最
我有一个网站,http://www.veluwenkamp.nl在底部的主页上,您可以找到 4 个列表项(图片)它们不能很好地对齐,它必须在一条水平线上。 我什么都试过了,还是不行。你们能给我一些建议
我正在尝试使用 Android Studio 中的“工具”命名空间功能。我正在尝试填充 ListView带有虚拟列表项,用于设计目的。链接here说 tools:listitem="@android:
我遇到了一个问题。我想学习一些关于 Firebase 等的知识。今天我制作了 RecyclerView,它应该显示我的 Firebase 数据库的项目。但是如果我运行它,我会得到这个错误: E/And
我有一个 ListView。我知道如何突出显示或更改 ListView 中所选项目的背景。但是我想像这样缩放所选项目: (选中的项目比这张图片中的其他列表项大一点) 有人可以帮我做吗? 最佳答案 我找
我的页面上有几个未排序的列表。两个列表都使用 list-style: disc inside;。每个列表的列表项中都有一对 div。问题是列表项的内容占用多行,并且圆盘垂直显示在多行列表项的底部。 这
是否可以在不更新版本的情况下使用 Sharepoint Client ObjectModel 更新 Created/Modified 字段? var file = _ClientContext.Web
我正在使用React Native构建应用程序,并使用Jest和Enzyme进行单元测试。如何测试的renderItem()函数? 它从React-Native-Elements库返回一个。 让我给您
我在asp.net中使用下拉列表,它有代表下拉列表项目的ListItem集合,每个ListItem只有两个字段来保存数据,Value和Text字段,但这些还不够我想保存更多数据对于每个项目。让我们在附
我已经根据 AJAX 结果创建了列表。基本上动态地将项目添加到列表中。但是在第二次ajax调用时,列表项追加到以前的项目中。我想重新加载新列表。它应该包含第二次 ajax 调用的结果。 我想单独删除所
当列表元素 (ListItem) 的权限已更改时,我需要触发一个事件(或启动一个工作流)。 “ItemUpdating”/“ItemUpdated”不会触发(我想是因为 ListItem 本身没有更新
我正在尝试查找如何在我的 ListView 中删除我的 ListItems 的组件。实际上有一个适用于 iOS 的模块 react-native-swipeout 您可以在其中刷出元素。我需要相同的
我正在使用React Native和react-native-elements在侧边菜单中呈现选项列表,但是当我运行该项目时,ListItem中的onPress Prop code> 未能发挥应有的作
我是一名优秀的程序员,十分优秀!