我正在尝试使用 Y.StyleSheet 设置元素的样式。
这就是我目前正在做的事情,它工作正常:http: //jsfiddle.net/AxUMD/47/
document.documentElement.className += ' js';
Y.one('#techsolutionsCheckBox input[type=checkbox]').on('change', function (e) {
var target = e.currentTarget,
techSBox = Y.one('.box'),
techSBlueBox = document.getElementById( 'techsolutions' );
colourBlue = "#cee4f2",
colourWhite = "#ffffff";
if (target.get('checked')) {
techSBox.removeClass('hidden');
techSBlueBox.style.backgroundColor = colourBlue;
techSBlueBox.style.width = "380px";
techSBlueBox.style.height = "100px";
} else {
techSBox.addClass('hidden');
techSBlueBox.style.backgroundColor = colourWhite;
techSBlueBox.style.width = null;
techSBlueBox.style.height = null;
}
});
但这就是我想做的事情:http: //jsfiddle.net/AxUMD/57/ 但它没有像我想象的那样工作。
document.documentElement.className += ' js';
Y.one('#techsolutionsCheckBox input[type=checkbox]').on('change', function (e) {
var target = e.currentTarget,
techSBox = Y.one('.box'),
techSBlueBox = Y.one(Y.DOM.byId("#techsolutions")),
changesChecked = { background-color : '#cee4f2', width : '380px', height : '100px' },
changesUnChecked = { background-color : '#ffffff', width : null, height : null },
currentStyle = techSBlueBox.getStyle('cssText');
if (target.get('checked')) {
techSBox.removeClass('hidden');
techSBlueBox.setStyle('cssText', Y.StyleSheet.toCssText(changesChecked, currentStyle));
} else {
techSBox.addClass('hidden');
techSBlueBox.setStyle('cssText', Y.StyleSheet.toCssText(changesUnChecked, currentStyle));
}
});
任何帮助将不胜感激。
谢谢