teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

追記

2019/05/11 07:14

投稿

nana_ton
nana_ton

スコア39

title CHANGED
File without changes
body CHANGED
@@ -57,7 +57,7 @@
57
57
  });
58
58
  ```
59
59
 
60
- 追記
60
+ 追記:match()とjoin()をinnerHTMLで処理する
61
61
  ```ここに言語を入力
62
62
  $(function() {
63
63
  $.ajax({

2

コメントアウト追加

2019/05/11 07:14

投稿

nana_ton
nana_ton

スコア39

title CHANGED
File without changes
body CHANGED
@@ -86,7 +86,7 @@
86
86
  const testDom = document.createElement('div')
87
87
  testDom.innerHTML = description
88
88
  console.log(testDom);
89
- var descriptionText = testDom.innerText
89
+ var descriptionText = testDom.innerText  //constだと文字制限でエラー
90
90
  //
91
91
  // console.log(title);
92
92
  // console.log(date.getFullYear()+"年"+ (date.getMonth() + 1) + "月" + date.getDate() + "日");
@@ -95,7 +95,7 @@
95
95
  // console.log(fullwidth);
96
96
  // console.log(description);
97
97
 
98
- // letter limit
98
+ // 文字制限
99
99
  if(descriptionText.length>=70){
100
100
  descriptionText = descriptionText.substr(0,70)+'...'
101
101
  }

1

match()とjoin()をinnerHTMLで処理

2019/05/11 07:13

投稿

nana_ton
nana_ton

スコア39

title CHANGED
File without changes
body CHANGED
@@ -55,4 +55,51 @@
55
55
  output.find('ul').append('<li><a href="' + link + '">' + "<span class=date>" + datestr + "</span>" + "</br>" + " " + title + '</a>' + "</br>" + description + '</li>');
56
56
 
57
57
  });
58
+ ```
59
+
60
+ 追記
61
+ ```ここに言語を入力
62
+ $(function() {
63
+ $.ajax({
64
+ url: 'rss.php', //PHP name
65
+ xmlType: 'xml',
66
+ success: function(xml) {
67
+ var row = 0;
68
+ var data = [];
69
+ var nodeName;
70
+ var output = $('#rss'); //HTML element
71
+
72
+
73
+
74
+ output.wrapInner('<ul></ul>');
75
+ $(xml).find("item").each(function() {
76
+ var title = $("title", this).text();
77
+ // var date = new Date($("dc\:date", this).text());
78
+ var date = new Date($("pubDate", this).text());
79
+ var datestr = date.getFullYear()+"."+ (date.getMonth() + 1) + "." + date.getDate();
80
+ var link = $("link", this).text();
81
+ var description = $("description",this).text();
82
+ // var fullwidth = desc.match(/[^ -~。-゚]/g); //全角文字取得
83
+ // var description = fullwidth.join('');   //配列を文字列に
84
+
85
+ // dom構造を取り出す
86
+ const testDom = document.createElement('div')
87
+ testDom.innerHTML = description
88
+ console.log(testDom);
89
+ var descriptionText = testDom.innerText
90
+ //
91
+ // console.log(title);
92
+ // console.log(date.getFullYear()+"年"+ (date.getMonth() + 1) + "月" + date.getDate() + "日");
93
+ // console.log(link);
94
+ // console.log(desc);
95
+ // console.log(fullwidth);
96
+ // console.log(description);
97
+
98
+ // letter limit
99
+ if(descriptionText.length>=70){
100
+ descriptionText = descriptionText.substr(0,70)+'...'
101
+ }
102
+ output.find('ul').append('<li><a href="' + link + '">' + "<span class=date>" + datestr + "</span>" + "</br>" + " " + title + '</a>' + "</br>" + descriptionText + '</li>');
103
+
104
+ });
58
105
  ```