码迷,mamicode.com
首页 > Web开发 > 详细

js基本知识点回顾

时间:2017-08-13 00:04:05      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:script   asc   tin   ref   win   函数   dom   获取对象   out   

  JavaScript:  基本语法:  与c#语法基本一致,类型转换:var a= parseint(值): var b = parsefloat(值);  

        isNaN(值):判断是否是数字,是返回false不是返回true;   

     函数方法:

//有返回值:
  <script >         
    var ccc =  test1(5,6);
         alert(ccc);
       function  test1(a,b){
   var c =  a+b;

  renturn  c;
}
  </script>
// 无返回值
    <script >         
     test1();
       function  test1(){

     alert(hello word);
}
      </script>

 

JavaScript DOM:

windows对象:

 window.open()     window.close()    window.opener  window.setinterval()/window.setTimeout();    

 调整页面:  window.navigate("url"); window.moverTo(x,y);   window.resizeTo(wid.hei); window.scrollTo(x,y);

window.open();:

<input type="button" value="按钮1" id="btn1"/>;
<script>

        var  oBtn1  =   document.getElementById("btn1");

        oBtn1.onclick = function(){

     window.open("Default2.aspx","_blank","width=400 height=400 left="+((window.screen.width/2)-200)+" top=""+((window.screen.height/2)-200)+");

//window.screen.width 是屏幕的宽度

}

  var  oBtn2  =   document.getElementById("btn2");

        oBtn2.onclick = function(){

         a.Close();
}

 oBtn1.onclick = function(){

    window.scrollTo(0,200);
}

//  往下调到200.相当于锚点

//将父级窗口关闭  widow.opener.close();

</script>

 

window.history 对象:

   window.history.back();  window.history.forward();  window.history.go(n);   //放正数前进一个页面,放负数后退一个页面;

window.location对象:

   window.location.href="url";    //跳转页面  和window.open();相似;但是浏览器不会屏蔽他,open有的浏览器会屏蔽;  它还会获取当前页面的地址;

window.document对象:

获取对象:

<script>
    document.getElementById("id")

    document.getElementsByClassName("class")

    document.getElementsByName("name")

    document.getElementsByTagName("标记")
</script>

操作对象属性:

添加属性:对象.setAttribute("name","value");

移除属性:对象.removeAttribute("name");

获取属性值:对象.getAttribute("name");

 

操作对象内容:

对象.innerHTML=“” /对象.innerText ="";

innerHTML会将里面写的有关的代码编译出来而Text会将你写的内容当做文本展示出来并不会编译。

普通元素:

移除内容:对象.innerHTML="" / inner.Text=""

获取内容:对象.innerHTML

 

js基本知识点回顾

标签:script   asc   tin   ref   win   函数   dom   获取对象   out   

原文地址:http://www.cnblogs.com/liuyubin0629/p/7351830.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!