项目中使用到的前端知识点

版权声明:作品为本人原创,如需转载,请注明出处 aa15237104245的博客 https://blog.csdn.net/aa15237104245/article/details/82012007

1 设置跳转

如果一个超链接,点击之后不做任何事情, <a href="javascript:void(0);">

<a href="javascript:void(0);">

如果设置为 #  ,如果有滚动条,会跳转到顶部

2 json对象

JSON.parse(data);----从json字符串转换成json对象
$.parseJSON(data);----从json字符串转换成json对象
JSON.stringify();----把json对象转换成json字符串

Json的简单介绍 
从结构上看,所有的数据最终都可以分成三种类型: 
第一种类型是scalar(标量),也就是一个单独的string(字符串)或数字(numbers),比如“北京”这个单独的词。 
第二种类型是sequence(序列),也就是若干个相关的数据按照一定顺序并列在一起,又叫做array(数组)或List(列表),比如“北京,东京”。 
第三种类型是mapping(映射),也就是一个名/值对(Name/value),即数据有一个名称,还有一个与之相对应的值,这又称作hash(散列)或dictionary(字典),比如“首都:北京”。 
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它的规则非常简单并且是有趣的: 
1) 并列的数据之间用逗号(“,”)分隔。 
2) 映射用冒号(“:”)表示。 
3) 并列数据的集合(数组)用方括号("[]")表示。 
4) 映射的集合(对象)用大括号(“{}”)表示。 
按照这个规则可以作以下理解: 
1.数组用“[]”创建,对象用“{}”创建,并且使用Json基本都是用[]或者{}创建的数组或对象,否则一个普通的字符串是没有意义的; 
2.无论是数组还是对象,之间的元素都用“,”隔开; 
3.对象内部,(属性的)名称和值用“:”隔开,并且必须要用“:”隔开,不可单独存在属性名或者值; 
4.对象和数组可以互相嵌套,即数组中的一个元素可以是一个对象也可以是一个数组,同理对象中的一个属性的值可以是一个对象也可以是一个数组。

3 jquery 字符串截取操作

var str="ssssss.aa"

str=str.substr(0, str.indexOf("."))

4 jquery tabs()

使得3个tab 点击可以替换内容 

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>jQuery UI 标签页(Tabs) - 默认功能</title>
  <link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
  <script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
  <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
  <link rel="stylesheet" href="http://www.runoob.com/try/demo_source/jqueryui/style.css">
  <script>
  $(function() {
    $( "#tabs" ).tabs();
  });
  </script>
</head>
<body>
 
<div id="tabs">
  <ul>
    <li><a href="#tabs-1">Nunc tincidunt</a></li>
    <li><a href="#tabs-2">Proin dolor</a></li>
    <li><a href="#tabs-3">Aenean lacinia</a></li>
  </ul>
  <div id="tabs-1">
   1
	</div>
  <div id="tabs-2">
  2</div>
  <div id="tabs-3">
 3 </div>
</div>
 
 
</body>
</html>

 

设置再次点击,折叠tab

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI 标签页(Tabs) - 折叠内容</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
  <script>
  $(function() {
    $( "#tabs" ).tabs({
//允许折叠
      collapsible: true
    });
  });
  </script>
</head>

js中的四舍五入

NumberObject.toFixed(num)
例如 
1/3 保留3位小数
   (1/3).toFixed(3)

 避免出现undefined 

var temp = conditionData.temp;
			
//null or undefined or NaN
			if(!temp){
				temp = weatherData.wendu ? weatherData.wendu : " " ;
			}


日期格式化
 

function formatDate(time,format='YY-MM-DD hh:mm:ss'){
    var date = new Date(time);

    var year = date.getFullYear(),
        month = date.getMonth()+1,//月份是从0开始的
        day = date.getDate(),
        hour = date.getHours(),
        min = date.getMinutes(),
        sec = date.getSeconds();
    var preArr = Array.apply(null,Array(10)).map(function(elem, index) {
        return '0'+index;
    });////开个长度为10的数组 格式为 00 01 02 03

    var newTime = format.replace(/YY/g,year)
                        .replace(/MM/g,preArr[month]||month)
                        .replace(/DD/g,preArr[day]||day)
                        .replace(/hh/g,preArr[hour]||hour)
                        .replace(/mm/g,preArr[min]||min)
                        .replace(/ss/g,preArr[sec]||sec);

    return newTime;         
}
formatDate(new Date().getTime());//2017-05-12 10:05:44
formatDate(new Date().getTime(),'YY年MM月DD日');//2017年05月12日
formatDate(new Date().getTime(),'今天是YY/MM/DD hh:mm:ss');//今天是2017/05/12 10:07:45

js获取前一天

new Date().getTime()-3600*24*1000

猜你喜欢

转载自blog.csdn.net/aa15237104245/article/details/82012007