[英]run jQuery when HTML is loaded
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代碼是否應該在頁面加載時運行,即在此處顯示的方式? 我使用的是尾聲2。jQuery保存為.js文件,而html保存為.html。 這兩個文件位於同一目錄中。
感謝您提供的所有幫助!
確保在index.html
頁面的<head>
中定義了指向javascript文件的鏈接。
<script rel="javascript" type="text/javascript" src="path/to/javascript.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.