简体   繁体   中英

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 . 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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