Javascript HTML中的多个加载错误

Javascript HTML中的多个加载错误,javascript,html,Javascript,Html,HTML:- 在body标记中,我使用了onload=“variable2.init();variable1.init();” JavaScript:- var variable1 = { rssUrl: 'http://feeds.feedburner.com/football-italia/pAjS', init: function() { this.getRSS(); }, getRSS: function() { jQuery.getFeed({ ur

HTML:-

在body标记中,我使用了
onload=“variable2.init();variable1.init();”

JavaScript:-

var variable1 = {
rssUrl: 'http://feeds.feedburner.com/football-italia/pAjS',

init: function() {
    this.getRSS();
},

getRSS: function() {
    jQuery.getFeed({
        url: variable1.rssUrl,
        success: function showFeed(feed) {
            variable1.parseRSS(feed);
        }
    });
},

parseRSS: function(feed) {
    var main = '';
    var posts = '';
    var className = 'even';
    var pst = {};
    for (i = 0; i < feed.items.length; i++) {
        pst = variable1.parsefootballitaliaRSS(feed.items[i]);
        if (className == 'odd') {
            className = 'even';
        }
        else {
            className = 'odd';
        }
        var shorter = pst.story.replace(/<(?:.|\n)*?>/gm, '');
        item_date = new Date(feed.items[i].updated);
        main += '<div id="content1" class="post-main ' + className + '" onclick="mwl.setGroupTarget(\'#screens1\', \'#blog_posts1\', \'ui-show\', \'ui-hide\');mwl.setGroupTarget(\'#blog_posts1\', \'#post' + (i+1) + '\', \'ui-show\', \'ui-hide\');">';
        main += '<b>' + pst.title.trunc(55, true) + '</b><br />' + shorter.trunc(30, true);
        main += '<div class="datetime">' + item_date.getDateTime() + '</div></div>';

        posts += '<div class="post-wrapper ui-hide" id="post' + (i+1) + '">';
        posts += '<div class="post-title"><b>' + pst.title + '</b></div>';
        posts += feed.items[i].description;
        posts += '</div>';
    }

    jQuery('#main_screen1').html(main);
    jQuery('#blog_posts1').html(posts);

},

parsefootballitaliaRSS: function(item) {
    var match = item.description.match('src="([^"]+)"');
    var part = item.description.split('<font size="-1">');
    var arr = {
        title: item.title,
        link: item.link,
        image: match,
        site_title: item.title,
        story: item.description
    };

    return arr;
}
};

var variable2 = {
    weatherRSS: 'http://feeds.feedburner.com/go/ELkW',

    init: function() {
        this.getWeatherRSS();
    },

    getWeatherRSS: function() {
        jQuery.getFeed({
            url: variable2.weatherRSS,
            success: function showFeed(feed) {
                variable2.parseWeather(feed);
            }
        });
    },

    parseWeather: function(feed) {
        var main = '';
        var posts = '';
        var className = 'even';
        var pst = {};
        for (i = 0; i < feed.items.length; i++) {
            pst = variable2.parsegoRSS(feed.items[i]);
            if (className == 'odd') {
                className = 'even';
            }
            else {
                className = 'odd';
            }
            var shorter = pst.story.replace(/<(?:.|\n)*?>/gm, '');
            item_date = new Date(feed.items[i].updated);
            main += '<div id="content2" class="post-main ' + className + '" onclick="mwl.setGroupTarget(\'#screens2\', \'#blog_posts2\', \'ui-show\', \'ui-hide\');mwl.setGroupTarget(\'#blog_posts2\', \'#post' + (i+1) + '\', \'ui-show\', \'ui-hide\');">';
            main += '<b>' + pst.title.trunc(55, true) + '</b><br />' + shorter.trunc(30, true);
            main += '<div class="datetime">' + item_date.getDateTime() + '</div></div>';

            posts += '<div class="post-wrapper ui-hide" id="post' + (i+1) + '">';
            posts += '<div class="post-title"><b>' + pst.title + '</b></div>';
            posts += feed.items[i].description;
            posts += '</div>';
        }

        jQuery('#main_screen2').html(main);
        jQuery('#blog_posts2').html(posts);

    },

    parsegoRSS: function(item) {
        var match = item.description.match('src="([^"]+)"');
        var part = item.description.split('<font size="-1">');
        var arr = {
            title: item.title,
            link: item.link,
            image: match,
            site_title: item.title,
            story: item.description
        };

        return arr;
    }
};
var variable1={
苏尔:'http://feeds.feedburner.com/football-italia/pAjS',
init:function(){
这个.getRSS();
},
getRSS:function(){
jQuery.getFeed({
url:variable1.rssUrl,
成功:函数showFeed(feed){
变量1.parsers(提要);
}
});
},
parseRSS:函数(提要){
var main='';
var posts='';
var className='偶数';
var pst={};
对于(i=0;i'+shorter.trunc(30,真);
main+=''+项_date.getDateTime()+'';
职位+=”;
posts+=''+pst.title+'';
posts+=feed.items[i].说明;
职位+=”;
}
jQuery('#main_screen1').html(main);
jQuery('#blog_posts1').html(posts);
},
足球运动员:功能(项目){
var match=item.description.match('src=“([^”]+)”);
var部分=项目描述分割(“”);
var arr={
标题:item.title,
链接:item.link,
图片:match,
站点标题:item.title,
故事:item.description
};
返回arr;
}
};
变量2={
weatherRSS:'http://feeds.feedburner.com/go/ELkW',
init:function(){
这个.getWeatherRSS();
},
getWeatherRSS:function(){
jQuery.getFeed({
url:variable2.weatherRSS,
成功:函数showFeed(feed){
变量2.天气(饲料);
}
});
},
parseWeather:函数(提要){
var main='';
var posts='';
var className='偶数';
var pst={};
对于(i=0;i'+shorter.trunc(30,真);
main+=''+项_date.getDateTime()+'';
职位+=”;
posts+=''+pst.title+'';
posts+=feed.items[i].说明;
职位+=”;
}
jQuery('#main_screen2').html(main);
jQuery('#blog_posts2').html(posts);
},
parsegoRSS:函数(项){
var match=item.description.match('src=“([^”]+)”);
var部分=项目描述分割(“”);
var arr={
标题:item.title,
链接:item.link,
图片:match,
站点标题:item.title,
故事:item.description
};
返回arr;
}
};
当我运行程序时,它只读取一个变量,即1或2。
如何更正它们以读取这两个变量?

试试这个

<body onload="callFunctions()">
更新-

希望它能帮助你。

用这个

<script type="text/javascript">
 window.onload = function() {  

  variable1.init(); 
  variable2.init();

 }
</script>

window.onload=函数(){
variable1.init();
variable2.init();
}

我只在html中尝试了上述代码,但仍然存在问题。我们是否也需要在js文件中使用window.onload代码?@user2326438是否添加外部js文件?@user2326438确定。然后你想在js files.yes中添加window.onload,因为我在HTML文件中添加了上述代码,但它的读数为variable1或variable2。我正在使用列表项树布局创建移动应用程序。在这里,当我单击项目1时,它应该是variable1,其中包括博客链接“”,类似地,我尝试对项目2执行此操作,但当我在HTML中同时使用variable1和variable2时,会导致一个问题。
<script type="text/javascript">
 window.onload = function() {  

  variable1.init(); 
  variable2.init();

 }
</script>