如何通过条件停止事件

时间:2016-01-13 09:39:10

标签: javascript

我有这个功能,我需要点击'输入值达到0且更少

后停止的事件
 function clickPlus(e) {
                  var parent = e.target.parentNode,
                      span = parent.querySelector('span'),
                      input = parent.getElementsByTagName('input')[0],
                      inner = span.dataset.one,
                      price = inner * (++parent.querySelector('input').value);          
                      span.innerHTML = price; // price takes an input value
                      if (price > 10){
                         return false; // error here 
                      }         
                      countPrice();                  
                }
            for(i=0; i<pluses.length; i++) eventsObj.addEvent(pluses[i],'click', clickPlus);

2 个答案:

答案 0 :(得分:-1)

&#39; countPrice&#39;无论if语句如何,函数都会触发。

使用if语句尝试反过来或添加其他...

if(price>0)
{
    countPrice();
}

答案 1 :(得分:-1)

pluses[i]

取消绑定点击事件

您可以通过调用jquery unbind / off方法取消绑定。

$(pluses[i]).off('click');

没有给出pluses[i]的值,所以我将把这个值称为加号[i]本身。

For more info - SO

jquery off method