【发布时间】:2014-11-10 16:50:20
【问题描述】:
我正在尝试为我的对象编写一个方法,该方法侦听要单击的按钮,并根据单击的按钮在 1 和 0 之间切换相应的对象属性。我可能偏离了轨道,但我可以用一种方法和“this”关键字?我下面的代码是我的进度,但我卡住了。http://jsfiddle.net/eh8L5cg1/
<input type="button" id="buttonOne" value="toggle buttonOne" />
<input type="button" id="buttonTwo" value="toggle buttonTwo" />
<input type="button" id="buttonThree" value="toggle buttonThree" />
var controlPannel = {
buttonOne : 0,
buttonTwo : 0,
buttonThree : 0
toggleState: function() {
$('button').click( function() {
if (controlpannel.this == 0 ) {
controlpannel.this = 1;
} else {
controlpannel.this = 0;
}
});
}
}
【问题讨论】:
标签: javascript html object methods logic