js处理数据的方式记录

条件判断

JavaScript把null、undefined、0、NaN和空字符串''视为false,其他值一概视为true。

js中常用的数据处理记录

//下拉框选中项的内容
$("#subsidyType option:selected").text();
//IE有时处理中文乱码
var _borrowName = encodeURIComponent($.trim($("#userName").val()));
window.open(encodeURI('http://api.xxx.cn/share/qqim?url=${weburl}/user/register.html?ui=${ui}&title=我在某某某网站帮你抢到注册壕礼&summary=快来领取和我一起赚钱吧!'));
// input控件选择器
$("input[name='username']")
// 连续对一个对象的属性处理
$(".offline_on_detail").attr("style","display:none").attr("data-status","off");

时间工具

//时间处理文件-------------------------------------------------------------
var now = new Date(); //当前日期   
var nowDayOfWeek = now.getDay(); //今天本周的第几天   
var nowDay = now.getDate(); //当前日   
var nowMonth = now.getMonth(); //当前月   
var nowYear = now.getYear(); //当前年   
nowYear += (nowYear < 2000) ? 1900 : 0;
//格局化日期:yyyy-MM-dd   
function formatDate(date) {   
    var myyear = date.getFullYear();   
    var mymonth = date.getMonth()+1;   
    var myweekday = date.getDate();  

    if(mymonth < 10){   
        mymonth = "0" + mymonth;   
    }   
    if(myweekday < 10){   
        myweekday = "0" + myweekday;   
    }   
    return (myyear+"-"+mymonth + "-" + myweekday);   
}  
//获得本周的开端日期   
function getWeekStartDate() {   
    var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek+1);   
    return formatDate(weekStartDate);   
}  

//获得本周的停止日期   
function getWeekEndDate() {   
    var weekEndDate = new Date(nowYear, nowMonth, nowDay + (7 - nowDayOfWeek));   
    return formatDate(weekEndDate);   
}