小编Ben*_*Ben的帖子

jQuery'每个'循环与JSON数组

我正在尝试使用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)

javascript each jquery json

27
推荐指数
3
解决办法
10万
查看次数

如何在javascript中清除div的文本内容?

我正在临时将内容添加到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的临时内容的解决方案?

html javascript jquery

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×2

jquery ×2

each ×1

html ×1

json ×1