3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScript(jQuery使用)でRSSフィードを取得して切り替える例

Last updated at Posted at 2015-11-29

前提

以下の条件と同じです

JavaScript(jQuery使用)でRSSフィードを取得するイケてるプラグイン
http://qiita.com/selious/items/c82e3deac0bd838795b5

カスタマイズ内容

上記に対して、配列+selectボックスで動的に切り替えれるようにします。

コード例

rss_sample2.html
<html>
<head>
<link rel="stylesheet" href="jquery.zrssfeed.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="jquery.zrssfeed.js"></script>
<style>
.rssFeed{margin:2px;}#fe{overflow-y:scroll;}
</style>
</head>
<body>
<div>
	<div><select class="form-control" id="sel1"></select></div>
	<div id="fe"></div>
</div>
<script>
$(function(){
var Us =[ ["http://news.google.com/news?hl=ja&ned=us&ie=UTF-8&oe=UTF-8&output=rss","Google"]
	,["http://itpro.nikkeibp.co.jp/rss/develop.rdf","ITproソフト"]
	,["http://black-flag.net/feed","BlackFlag"]
	,["http://nikkeibp.jp/jp/flash/index.rdf","日経BP"]
];
</script>
<script>
$(document).ready(function(){
	if(typeof(RSS_LIST1)!="undefined"){
		Us=RSS_LIST1;
	}
	var u=Us[0][0],s=$('#sel1'),f=$('#fe');
	for(var i=0;i<Us.length;i++){
		s.append('<option value="'+Us[i][0]+'">'+Us[i][1]+'</option>');
	}
	f.css("height",500-50).rssfeed(u,{limit:10});
	s.on('click change',function(){
		f.rssfeed($(this).val());
	});
});
</script>
</body>
</html>

動作サンプル

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?