堂Di

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1、tofix(n)这个可以得到n位小数 但如果想要兼容的话 还是用字符串的截取来做吧

function changeTwoDecimal_f(x)  
{  
var f_x = parseFloat(x);  
if (isNaN(f_x))  
{  
    //alert('function:changeTwoDecimal->parameter error');  
    return false;  
    }  
    var f_x = Math.round(x*100)/100;  
    var s_x = f_x.toString();  
    var pos_decimal = s_x.indexOf('.');  
    if (pos_decimal < 0)  
    {  
        pos_decimal = s_x.length;  
        s_x += '.';  
    }  
    while (s_x.length <= pos_decimal + 2)  
    {  
        s_x += '0';  
    }  
    return s_x;  
}
var money = 1000;//比如这是1000(分) 要转化为XX.XX的格式来显示价钱
//var m = (money/100).toFixed(2);
var m = changeTwoDecimal_f(money/100); var y = Math.floor(m); var f = m.toString().split(".")[1];

2、我们在js下讲时间格式字符串格式化 在ff chrome ie8+可以正常显示 但在ie8-下 转化出来的是NaN....

//获取当天时间戳
function getCurDateTime()
{
    var date = new Date();
    var date_num = new Date(Date.UTC(date.getFullYear(),date.getMonth(),date.getDate()));
    return date_num.getTime()/1000;
}
var expire = '2014-07-05';
var now = getCurDateTime();
//var exp_end = new Date(expire).getTime()/1000; 这个在ie8-下转化成NaN 无法正常转换时间字符串
var exp_end = parseISO8601(expire).getTime()/1000;
var day = Math.ceil((exp_end - now)/(24*3600));//得到相差天数

3、class className 

在一个项目里面 td默认有样式名 td_def; 在对一些特别的td赋值样式名setAttribute('class','test_class') 发现在ie8-下样式没有起作用 而且用f12看到td是没有属性及内联样式的 赋值 outHTML到Notepad++里一看 发现其结构类似

<TD class=td_def class="test_class"></TD>

解决方法1

var table = $('#table').find('td');
table[i].setAttribute('class','test_class');//正常的
table[i].setAttribute('className','test_class');//给ie8-

解决方法2

用jq。。。。。好吧。。这也是方法 哈哈

posted on 2014-06-05 17:12  堂Di  阅读(482)  评论(0编辑  收藏  举报