如何替换初始化的对象? [英] How do I replace an initialized object?

查看:103
本文介绍了如何替换初始化的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下jQuery代码,这些代码是在页面加载时启动的.它开始播放幻灯片.

I have the following jQuery code which is initiated on page load. It starts a slideshow.

$(document).ready(function() {

    $.dothis({
        option:1,
        option:2,
        slides:[
            {image:'img1.jpg'},
            {image:'img2.jpg'}
        ]
    });

});

现在,我想在用户单击页面正文时添加/删除图像.如何在幻灯片:[]对象中添加/删除项目?或如何一起替换该对象?

Now I want to add/remove images when the users clicks the body of the page. How do I add/remove items to the slides:[] object? Or how do I replace this object all together?

推荐答案

var slideoptions = {
    option:1,
    option:2,
    slides:[
        {image:'img1.jpg'},
        {image:'img2.jpg'}
    ]
};

$(document).ready(function() {

    $.dothis(slideoptions);

});

// push new image into slides array
slideoptions.slides.push({ 'image' : 'someimg.jpg' });

这篇关于如何替换初始化的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆