我最近为我在 jQTouch 中开发的 iPhone 应用程序创建了一个 xml 提要 -> html javascript 函数。 Original教程和代码。
我想知道是否有人知道单击链接时刷新 xml 数据(再次获取提要)的快速简便方法。
例如。 在代码中:
<div id="btns">
<ul>
<li><a href="#feed">Go to feed</a></li> <!-- When i click this, I want the getDataFeed function to dump the data & rerun. -->
</div>
<div id="feed">
<div id="content_from_feed_inserted_here"></div>
</div>
在 javascript 中:
$(document).ready(function() {
function getDataFeed() {
$('.loadingPic').show(); // show progress bar
$.get('http://xxxxxxx.com/information.xml', function(d) {
$(d).find('location').each(function(){
var $location = $(this);
var the_data = $location.find('xml_data').text();
var collected_data = collected_data += '<span>' + the_data + '</span>' ;
$('#content_from_feed_inserted_here').empty().append($(collected_data)); // empty div first
$('.loadingPic').fadeOut(1400); // remove progress bar
});
}
// run on page load
getDataFeed();
// how do i also get it running when i click <li><a href="#feed">Go to feed</a></li>
});
非常感谢您的帮助!
最佳答案
测试这个:
将函数 getDataFeed() {..} 移到准备好的函数之外,并从链接捕获点击事件。在 <a>
中设置 id="feed".
function getDataFeed() {
$('.loadingPic').show(); // show progress bar
$.get('http://xxxxxxx.com/information.xml', function(d) {
$(d).find('location').each(function(){
var $location = $(this);
var the_data = $location.find('xml_data').text();
var collected_data = collected_data += '<span>' + the_data + '</span>' ;
$('#content_from_feed_inserted_here').empty().append($(collected_data)); // empty div first
$('.loadingPic').fadeOut(1400); // remove progress bar
});
}
$(document).ready(function() {
// how do i also get it running when i click <li><a href="#feed" id="#feed">Go to feed</a></li>
$('#feed').click(getDataFeed);
// run on page load
getDataFeed();
});
关于javascript - 单击刷新 XML 提要 (jQTouch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4030232/