jQuery的旋钮显示NaN当值为0 [英] jQuery Knob displays NaN when value is 0

查看:790
本文介绍了jQuery的旋钮显示NaN当值为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这真是不可思议。

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

这是我原来的code得到百分号展现出来,伟大的工程。出于某种原因,当值为0时,在页面加载它显示为 NaN的。奇怪的是,只有当你突出显示文本,然后单击关闭它显示为0的实际值(替换 NaN的值)。任何想法是什么原因造成这种情况?我试图处理它的格式挂钩:

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 + '%';
           }
        } 
    });
});

它仍然无法正常工作。我的控制台登录,我传递的价值,果然是0,我想它可能会前,Y X载荷是一个,因此看到了价值不确定,因为我在value属性很路过一个angularJS数据绑定。但我想它处理无济于事。对此有何想法的?

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?

推荐答案

价值== NaN的将无法工作,因为,出人意料的是,在JavaScript 为NaN 不等于 NaN的。尝试 isNaN()代替

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

这篇关于jQuery的旋钮显示NaN当值为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆