Changing property of label with a function does not work
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'
});
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.
精彩评论