我正在制作一个番茄钟,我正在尝试检测点击增加按钮的位置,如果它在会话设置器上然后增加sessionVal,否则如果不是那么警告某些东西(只是一个测试,看看它是否正在通过检测.increase(this)parent尝试执行此操作...当我单击session-setter上的.increase按钮时,sessionVal会增加,但是当我单击break-setter上的.increase按钮时,sessionVal会增加也不是警告错误..
我的剧本
$(".increase").on('click', function(e) {
e.preventDefault();
console.log($(this).parent().parent()) // this logged .increase parent parent session-setter and break-setter, but when .increase button on break-setter is click sessionVal stills increment instead of alerting error
if($(this).parent().parent("#session-setter") && onSession){
sessionVal+=1;
counter =0;
$(this).parent().children("#session-value").html(sessionVal);
}else{ //if another from another parent
alert("error"); //just a test to see if else is being detected
}
})
我的HTML
<div class="control-wrapper">
<div id="break-setter">
<h2>Break Length</h2>
<div class="break-controllers">
<button class="decrease">-</button>
<span id="break-value">5</span>
<button class="increase">+</button>
</div>
</div>
<div id="session-setter">
<h2>Session Length</h2>
<div class="session-controllers">
<button class="decrease">-</button>
<span id="session-value">25</span>
<button class="increase">+</button>
</div>
</div>
</div>