需要帮助使用MVC调用和运行复杂对象属性

时间:2019-02-11 20:45:34

标签: javascript object dom model-view-controller

有人告诉我要将我的代码传输到MVC,但这样做时遇到了问题。

我需要按以下所示方式进行操作:

var model = {
    demo: document.getElementById('demo'),
    colour: document.getElementsByTagName('li').item(0),
    size: document.getElementsByTagName('li').item(1),
    visible: document.getElementsByTagName('li').item(2),
    position: document.getElementsByTagName('li').item(3),
    swap: document.getElementsByTagName('li').item(4),
    report: document.getElementsByTagName('li').item(5)
};

var demoOn = model.demo.onmouseover;
var demoOff = model.demo.onmouseout;

var view = {
    col: {newCol: model.demo.style.backgroundColor = 'rebeccapurple', oldCol: model.demo.style.backgroundColor = 'darkcyan'},
    siz: {newSiz: model.demo.style.width = '600px', oldSiz: model.demo.style.width = '400px'},
    vis: {newVis: model.demo.style.opacity = '0', oldVis: model.demo.style.opacity = '1'},
    pos: {newPos: model.demo.style.margin = '0 0 0 200px', oldPos: model.demo.style.margin = '0'}
};

var controller = {
    changeCol: function() {
        demoOn = function () {
            return view.col.newCol;
        }
    }
};
controller.changeCol();

https://jsfiddle.net/meys5x6n/

我希望一旦元素颜色属性悬停在div演示上,它就可以更改div演示的背景颜色。

0 个答案:

没有答案