我有此列表,该列表是动态生成的,并且跨度为id =“ #profileName”。因此页面中有多个列表,并且都具有该范围。这是列表:
htmltxt += '<li class="w3-row w3-margin-bottom w3-border-0 w3-round-large" style="width:80%;margin:auto">';
htmltxt += '<div class="w3-col w3-padding" style="width:50%">';
htmltxt += '<img class="avatar" style="margin-right:30px" src="images/Users-User-Male-icon.png">';
htmltxt += '<span id="profileName" class="w3-text-black"></span>';
htmltxt += '</div>';
htmltxt += '<div class="w3-col w3-round-large w3-indigo w3-border-0 w3-padding" style="width:50%">';
htmltxt += '<div id="replyDiv" class="w3-col w3-indigo w3-border-0 w3-padding" style="width:90%">';
htmltxt += '<div class="w3-row">';
if (myObj[x].replyMsg !== null) {
htmltxt += '<span class="w3-medium w3-col w3-white w3-round w3-row-padding w3-text-black" style="width:90%;word-wrap:break-word;white-space: pre-wrap;border-left:3px solid indigo">' + myObj[x].replyMsg + ' </span>';
}
htmltxt += '<div id="listDiv" class="w3-medium w3-col w3-text-light-grey" style="width:90%;word-wrap:break-word;white-space: pre-wrap;">' + myObj[x].msgContent + ' </div>';
htmltxt += '</div>';
htmltxt += '</div>';
htmltxt += '<div id="colDiv" class="w3-col w3-indigo w3-border-0 w3-padding" style="width:10%">';
htmltxt += '<div id="btnDiv" class="w3-row">';
htmltxt += '<button id="menuBtn" class="w3-button w3-circle w3-col w3-ripple w3-right"><span id="spanDel" class="w3-hide">' + myObj[x].msgId + ',' + myObj[x].userId + '</span><i class="fa fa-ellipsis-v" aria-hidden="true"></i></button>';
htmltxt += '<input id="msgCheck" class="w3-check" style="display:none;padding:8px 16px;" type="checkbox">';
htmltxt += '</div>';
htmltxt += '</div>';
htmltxt += '<div class="w3-row">';
htmltxt += '<span id="listSpan" class="w3-small w3-margin-left w3-text-light-grey">' + myObj[x].date + ' ' + myObj[x].time + ' ' + '</span>';
htmltxt += '</div>';
htmltxt += '</div>';
htmltxt += '</li>';
我正在使用此jquery代码使用此代码在该范围内插入内容:
$.post("flist.jsp", function (data) {
var myObj, x;
myObj = jQuery.parseJSON(data);
htmltxt = '', htmlname = '', forwardtxt = '';
for (x in myObj) {
htmltxt += '<li class="w3-white" style="padding:0">'
+ '<a id="anchorName" class="w3-button w3-bar-item w3-border w3-justify" href="msg.jsp?uid=' + myObj[x].userId + '">' + myObj[x].firstName + ' ' + myObj[x].lastName + '</a>'
+ '</li>';
forwardtxt += '<li class="w3-white" style="padding:0">'
+ '<span id="fsendSpan" class="w3-bar-item w3-border w3-justify" uid=' + myObj[x].userId + '><input id="forwardCheck" type="checkbox"> <i class="fa fa-user-circle-o fa-lg" aria-hidden="true"></i> ' + myObj[x].firstName + ' ' + myObj[x].lastName + '</span>'
+ '</li>';
if (myObj[x].userId === ${param.uid}) {
htmlname = myObj[x].firstName + ' ' + myObj[x].lastName;
}
}
$("#spanName").append(htmlname);
$("[id='profileName']").append(htmlname);
$("#myUL").append(htmltxt);
$("[id='forwardDiv']").children("#forwardList").html(forwardtxt);
});
大多数情况下,它不会显示该范围内的内容,但有时会以随机的方式出现,因为我一次又一次地重新加载页面