2012-11-26 55 views
0

我正在製作新聞應用,並且使用名爲zRSSFeed的jQuery插件。該插件提供了一項功能,可通過從下拉列表中選擇新聞來源來更改顯示的RSS提要,該功能將更改顯示在結果Div中的提要(請參閱示例here)。通過從鏈接列表中選擇訂閱源動態加載訂閱源

的源代碼:

<script src="http://jquery/1.7.1/jquery.min.js" type="text/javascript"></script> 
<script src="jquery.zrssfeed.min.js" type="text/javascript"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
    setRSSFeed('#menu'); 
    $('#menu').change(function() { 
     setRSSFeed(this) 
    }); 
    function setRSSFeed(obj) { 
     var feedurl = $('option:selected', obj).val(); 
     if (feedurl) { 
     $('#result').rssfeed(feedurl); 
     } 
    } 
    }); 
</script> 
<select id="menu">  
    <optionvalue="http://feeds.reuters.com/reuters/oddlyEnoughNews">News</option> 
    <option value="http://feeds.bbc.co.uk/iplayer/highlights/tv/list">BBC </option> 
    <option value="http://rss.cnn.com/rss/edition.rss">CNN News</option> 
</select> 
<div id="result"></div> 

我的問題是,而不是改變從下拉列表中選擇一個newSource的顯示的料,我很想通過選擇與指定的新源鏈接(HREF)來改變它們。

回答

0

不使用該

<select id="menu">  
    <optionvalue="http://feeds.reuters.com/reuters/oddlyEnoughNews">News</option> 
    <option value="http://feeds.bbc.co.uk/iplayer/highlights/tv/list">BBC </option> 
    <option value="http://rss.cnn.com/rss/edition.rss">CNN News</option> 
</select> 

。使用本

<script type="text/javascript"> 
    $(document).ready(function() { 
    //setting default feed 
    setRSSFeed('http://feeds.reuters.com/reuters/oddlyEnoughNews'); 
    }); 
    function setRSSFeed(feedurl) { 
     if (feedurl) { 
      $('#result').rssfeed(feedurl); 
       } 
       } 
      }); 
</script> 

    <a href="#" onclick="setRSSFeed('http://feeds.reuters.com/reuters/oddlyEnoughNews');">News</a> 
    <a href="#" onclick="setRSSFeed('http://feeds.bbc.co.uk/iplayer/highlights/tv/list');">BBC</a> 
    <a href="#" onclick="setRSSFeed('http://rss.cnn.com/rss/edition.rss');">CNN News</a>  
+0

其不工作...我是新手,請寫出來的一切顯然謝謝! –

+0

你可以請現在檢查我已經更新了答案 –

+0

謝謝sheldon它的工作! –