简体   繁体   English

当值为0时,jQuery旋钮显示NaN

[英]jQuery Knob displays NaN when value is 0

It's really weird. 真的很奇怪

$(function(){
    $('.dial').knob({
       return value + '%';
    });
});

That was my original code to get the percent sign to show up, which works great. 那是我原始的代码,用于显示百分号,效果很好。 For some reason, when the value is 0, on page load it displays as NaN . 由于某些原因,当该值为0时,在页面加载时显示为NaN The weird thing is that only once you highlight the text and then click off does it show the actual value of 0 (replacing the NaN value). 奇怪的是,只有突出显示文本然后单击关闭,它才会显示实际值0(替换NaN值)。 Any idea what is causing this to happen? 知道是什么原因导致这种情况发生的吗? I tried to handle it in the format hook: 我试图用格式挂钩处理它:

$(function(){
    $('.dial').knob({
       'format': function( value ){
           if(value == undefined || value == NaN {
             value = 0; 
             return value + '%';
           }
           else{
             return value + '%';
           }
        } 
    });
});

It still doesn't work. 它仍然不起作用。 I console logged the value I'm passing in, and sure enough it is 0. I'm thinking it may be an 'x loads before y' and therefore it sees the value as undefined, since I am passing in the value attribute by an angularJS data binding. 我用控制台记录了我要传入的值,并确保它为0。我认为它可能是“ y之前的x加载”,因此它将值视为未定义,因为我通过传入了value属性angularJS数据绑定。 But I'm trying to handle it to no avail. 但我正在努力解决它,但无济于事。 Any thought's on this? 有什么想法吗?

value == NaN will not work because, surprisingly, in javascript NaN does not equal NaN . value == NaN将不起作用,因为令人惊讶的是,在javascript中NaN不等于NaN try isNaN() instead. 尝试isNaN()代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM