第三周JS接触学习

来源:互联网 发布:淘宝卖家如何代销上货 编辑:程序博客网 时间:2024/06/05 15:12

果然不及时整理,知识就会变得生疏。时间比较长了,可能花费的时间也多些吧

这周主要学习内容有git 和 js

一、 GIT

1、 git的基本工作命令

  • git clone 
  • git add 
  • git commit -m 'yyy'
  • git pull 
  • git push original master 第一次提交
  • git checkout -- 某个dir 或者某个file
  • git stage 
  • 编写.gitignore 文件 ,该文件可以不跟踪未被缓存下来的项目文件
  • git config --global user.name "shaoman.lhj"

  • git branch '分支名' ,自己创建一个分支时,第一次提交的格式 git push original 分支名
  • git checkout 分
  • git branch -D 分知名 删除一个分支
  • git push origin --delete <branchName> 删除一个远程分支

2、  git pull request 是很好的code reviewer 工具,你pull request之后会向对应的人发送消息

二、 JS

1、 日期获取

 获取一个月的日期天数,可以使用 getDate , getDay 是获取一周内的第几天

var today = new Date() ;

如果往前推算5天,则可以使用

today.setDate(today.getDate() + 5) ; // 和 java中有点不同

往后负数即可

同样,增加年或者月,可以使用

d.setMonth(d.getMonth()+5); // 

d.setFullYear(d.getFullYear()+5);
 
js getUTCMonth vs getMonth
     
    The UTC methods calculate their date assuming that the date object is of local time and date.      


2、 更改li 的显示内容

     li.html("ddd");

3、 js 中 没有 overload 

    如果有一个参数无需传入,可以放着不传,但是只适用于最后一个参数不存在。 

4、怎么判断某个JS已经加载过来了,
        
     目前最简单的一个方法:

 比如 判断 Zepto 是否已经加载完毕,使用
     if(typeof  Zepto == undefined){}
使用场景:
判断某个JS加载完毕,才开始执行的函数;并且如果现在确实没加载完毕,则需要等一会儿再执行
if(isZeptoOK()){
            homeinit();
        } else{
           timer = setInterval(function (){
                        if(isZeptoOK()){
                            clearInterval(timer);
                            homeinit();
                        }
                    }
                  ,30);
        }
这种同样可以使用到 防止JS 动态重复加载 , 


5、onload 的使用

onload 是 加载完所有的页面元素,包括图片等,之后的执行,是所有浏览器都会有的一个方法
ready  是 加载完普通的dom结构就可以执行的,只存在jquery 中

the ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded.

The onload event is a standard event in the DOM, while the ready event is specific to jQuery. The purpose of the ready event is that it should occur as early as possible after the document has loaded, so that code that adds funcionality to the elements in the page doesn't have to wait for all content to load.


onload 有时需要做多件事情,可是后面的onload会把前面的覆盖掉,应该怎么做呢?
为了防止覆盖别人的,下面就是onload的标准写法了。
var oldOnload = window.onload || function () {};window.onload = function (){    oldOnload();    // Do Something...}
|| function () {}
目的是为了防止,之前没有定义onload 事件,会出现js错误~ ~

6、JS编码问题     
     编辑文件(保存文件时)的编码 ——> html 页面中设置的编码 ——> 浏览器解析的编码
7、  Zepto js 的li click 事件
$(选择器).on('click' , callback)';
8、 在js中把一个number类型的赋值给元素的attr value ,再次取出来则会变成 字符串类型 注意  ,
      js 自带 parseInt 函数可以解析字符串 直接变成number值 

9、 判断是否为string 类型 的语句
        if(typeof todayTime === 'string'){

10、json 格式
http://www.kjson.com/ 验证下写的json格式是否正确     
下面是正确的格式
{
    "itemList": [
        {
            "itemId": "1999",
            "mainPicUrl": "../assets/imgs/zhu.jpg",
            "sideUpUrl": "../assets/imgs/tuanzi.png",
            "sideDownUrl": "../assets/imgs/sakura.jpg",
            "itemName": "团子大家族团子",
            "time": "1999999"
        },
        {
            "itemId": "1999",
            "mainPicUrl": "../assets/imgs/sabereye.jpg",
            "sideUpUrl": "../assets/imgs/saberjian.png",
            "sideDownUrl": "../assets/imgs/sabermotuo.jpg",
            "itemName": "誓约胜利之剑",
            "time": "1999999"
        }
    ]
}

11、 what does this mean 

this is a reference to the member that invokes the current function...

then you can wrap it in the jquery function $() to select it just like you would another selector.


12、what (funcion ($) {} mean in javascript
如果在jquery中 $ 表示jquery, zepto中 表示zepto 


附加:
 1、 一个css遗留问题

本来是当鼠标悬浮在li上时,字体就变大,然而实际效果却是,鼠标放上去,只是变粗和颜色变化,font-size并没有起作用,为什么呢?
因为

和其他选择器冲突了,上面有一个使用ID 的选择器#paimaidate li,优先级高于使用类型选择的优先级,导致这里无效
解决方法: 在下面的选择器中,增加 #paimaidate , 变成组合选择器

#paimaidate li{
    display: inline;
    font-family:"Arial Narrow";
    font-size: 20px;
    padding-right: 140px;
    line-height: 40px;
}
.homedate:hover{             // 修改成 #paimaidate .homedate:hover 即可
    font-weight: bold ;
    font-size: 28px ;
    color: #36C075;
}
2、 chrome 禁用 js
设置——内容设置—— javascript    

0 0
原创粉丝点击