0

我正在尝试使用 yql 显示来自谷歌新闻的 rss 提要。目前,如果您在表单中输入邮政编码,它会工作一次,但如果不刷新页面,我无法输入另一个邮政编码。任何帮助将不胜感激!
P1

        <script>   
        function top_stories(o){  
            var items = o.query.results.item;  
            var output = '';  
            var no_items=items.length; 

            for(var i = 0; i < 4; i++) {  
            var title = items[i].title;  
            var link = items[i].link;  
            var desc = items[i].description;  
           output += "<h3><a href='" + link + "'>"+title+"</a></h3>" + desc + "<hr/>";  
            }
         document.getElementById('results').innerHTML = output;    
         }  
         </script> 
    </head>
    <body>
        <form name="input" action="" method="get" id="zc">
        Zip Code: <input id="zip" type="text" name="zip">
    <input id ="zipbutton" type="Button" value="Submit"    onClick="showDiv(document.getElementById('zc').zip.value);" >

    <div id="results"  ></div> 
    <script id="yql"></script>
    <script>    
    function showDiv(zip) {             
    var a = "http://query.yahooapis.com/v1/public /yql?q=select%20*%20from%20rss%20where%20url%20%3D%20'http%3A%2F%2Fnews.google.com%2Fnews%3Fgeo%3D" + zip + "%26output%3Drss'%0A&format=json&diagnostics=true&callback=top_stories";
     document.getElementById("yql").setAttribute("src",a);                              
        }
    </script>
    </body>
4

1 回答 1

0

尝试<script>为每次点击创建新元素。

var script = document.createElement('script');
script.setAttribute("src", a);
document.getElementsByTagName('head')[0].appendChild(script);
于 2013-09-21T19:39:35.223 回答