我很确定我做错了什么,但仍然有什么办法可以根据窗口大小设置一个值?有什么方法可以动态地改变对象属性的值吗? JavaScript
这里是一个示例代码:
var setNewValue;
$(window).resize(function() {
if($(window).width() < 768) {
setNewValue = "less";
} else {
setNewValue = "more";
}
});
var createObject = function(property) {
this.property = property;
this.showProperty = function() {
document.write(this.property);
};
};
var example = new createObject(setNewValue);
example.showProperty();
//未定义
您是否调整窗口大小来触发事件处理程序? –
是的,必须根据窗口大小设置值 –
'setNewValue'和'property'不是对象。这就是为什么没有参考。 – Bergi