开发者

Changing property of label with a function does not work

开发者 https://www.devze.com 2023-04-12 05:17 出处:网络
I try to change the backgroundcolor of a label, by clicking on a button. I\'ve looked into this issue with my teacher, but we can\'t find the problem, everything seems to be normal. If I try to push a

I try to change the backgroundcolor of a label, by clicking on a button. I've looked into this issue with my teacher, but we can't find the problem, everything seems to be normal. If I try to push an alert, this does work, so it is not the eventhandler that is not working.

var label = Titanium.UI.createLabel({
    backgroundColor:'#00ff00',
    width:120,
    height:200,
    top:20
});

var btnRed = Ti.UI.createButton({
开发者_开发问答    title:'Red',
    top:250,
    height:50,
    width:100,
});

btnRed.addEventListener('click', function(e) {
    label.backgroundColor:'#ff0000'
});

Changing property of label with a function does not work


Use "=" instead of ":" for an assignment.

btnRed.addEventListener('click', function(e) {
    label.backgroundColor = '#ff0000';
});


Try changing...

label.backgroundColor:'#ff0000' 

to

label.backgroundColor = '#ff0000';

I believe this will work because in the upper section, you are creating an object with properties, so you can use the property : value syntax, but in the function you need to access and set the value by using the normal = operator.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号