0

jQuery:

$(document).ready(function(){

var url='http://query.yahooapis.com/v1/public/yql?q=select * from html where url=\'http://stackoverflow.com/\' and xpath=\'//div[@id="question-mini-list"]//h3//a                       \'&format=json&callback=?';

    $.getJSON( url, function(data){
        $.each(data.query.results.a, function(){       
            $('#stack').append('<div><a href="http://stackoverflow.com'+this.href +'">'+this.content+'</a></div>')          
        })
    })
});

HTML

<section id="stack">

</section>

jQuery 代码是从较早的帖子中借来的(谢谢!),但我的问题是:jQuery 代码不应该在页面加载时运行,它在此处显示的方式吗?我使用 coda 2。jQuery 保存为 .js 文件,html 保存为 .html。这两个文件位于同一目录中。

感谢您的任何帮助!

4

1 回答 1

1

确保在页面中定义了指向 javascript 文件的<head>链接index.html

<script rel="javascript" type="text/javascript" src="path/to/javascript.js"></script>
于 2013-06-16T20:41:21.460 回答