JS常用方法

  
function GetPercent(num, total) {
    /// <summary>
    /// 求百分比
    /// </summary>
    /// <param name="num">当前数</param>
    /// <param name="total">总数</param>
    num = parseFloat(num);
    total = parseFloat(total);
    if (isNaN(num) || isNaN(total)) {
        return "-";
    }
    return total <= 0 ? "0%" : (Math.round(num / total * 10000) / 100.00);
}
设置$.ajax({
  crossDomain: true
})
此时服务端端口要小于等于14000 

 图片轮播js示例:

next();
var step = 0;
function next()
{
  switch (step) {
    case 0:
     document.getElementById('btn_explode').onclick();
      break;
    case 1:
      document.getElementById('btn_tile').onclick();
      break;
    case 2:
            document.getElementById('btn_bars').onclick();
      break;
    case 3:
      document.getElementById('btn_cube').onclick();
      break;
       case 4:
      document.getElementById('btn_turn').onclick();
      break;
    default:
      step = -1;
      
  }
  ++step;
  if(step==5){
    step=0;
  }
  setTimeout(next, 2000);
}

 时间字符串如:("2015/09/09 12:12:00")转 2015/09/09

var t = new Date("2015/09/09 12:12:00");
alert(t.toLocaleDateString());

 jq 获取 table 指定列

var arr = [
];
$($0).find('tr:gt(0)>td:nth-child(2)').each(function (index) {
  arr.push({
    'key': index + 1,
    'title': this.innerText
  });
})
console.log(JSON.stringify(arr));

  

原文地址:https://www.cnblogs.com/gaocong/p/4911659.html