我正在尝试使用jQuery的each
循环来遍历此JSON并将其添加到div
命名#contentHere
.JSON如下:
{ "justIn": [
{ "textId": "123", "text": "Hello", "textType": "Greeting" },
{ "textId": "514", "text":"What's up?", "textType": "Question" },
{ "textId": "122", "text":"Come over here", "textType": "Order" }
],
"recent": [
{ "textId": "1255", "text": "Hello", "textType": "Greeting" },
{ "textId": "6564", "text":"What's up?", "textType": "Question" },
{ "textId": "0192", "text":"Come over here", "textType": "Order" }
],
"old": [
{ "textId": "5213", "text": "Hello", "textType": "Greeting" },
{ "textId": "9758", "text":"What's up?", "textType": …
Run Code Online (Sandbox Code Playgroud) 我正在临时将内容添加到div,tempDiv,并将其添加到附加到显示的div #contentHere的链接上.我需要清除tempDiv的内容,以便链接不会相互附加,创建一个不链接到任何地方的URL字符串.
$(document).ready(function(){
$.getJSON("data.php", function(data){
for(i = 0; i < 5; i++){
$("#tempDiv").append(data.justIn[i].dataLink+ ' ');
$("#contentHere").append("<a href=\"#tempDiv\">Click to go to the div link</a>");
//I need to clear the contents of tempDiv here
}
});
});
Run Code Online (Sandbox Code Playgroud)
我去的时候清除div的临时内容的解决方案?