jQuery Knob displays NaN when value is 0

岁酱吖の 提交于 2019-12-13 05:24:30

问题


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. 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). 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. But I'm trying to handle it to no avail. Any thought's on this?


回答1:


value == NaN will not work because, surprisingly, in javascript NaN does not equal NaN. try isNaN() instead.



来源:https://stackoverflow.com/questions/24614212/jquery-knob-displays-nan-when-value-is-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!