js

js:
html - 就是页面上有哪些东西,就给每一个东西取个名字
css - 设置界面上这些东西都是什么样
javascript - 界面上这些东西的动画效果,数据获取及交互

脚本语言,与C#很相近

顺序语句、分支语句、循环语句

顺序语句 - 如果你要取某一个元素进行操作,1、将JS代码写在元素的下部,2、window.onload事件中
分支 - if...else if...else..
循环 - for(var i = 0;i<=10;i++){循环体};

定义变量 - var a =‘aaa’, var a = 10,
数组 - 不固定类型,不固定长度 , a.length

函数 - function 函数名(){ };

JS的DOM操作:
一、window:
1、window.onload

2、window.open(1,2,3,4) - 打开新页面,
1 - 打开页面的地址:'http://www......'
2 - target:_blank 新页面中打开
3 - 打开窗口的样式,toolbar=no:没有工具栏; menubar=no:无菜单栏;status=no:无状态栏;
width,height:打开时的宽度和高度;
left=100:打开窗口距离屏幕的左边距;
resizable=no:打开的窗口大小不可调;
scrollbars=no;不出现滚动条;
location=no;不出现地址栏;

注意:window.open('xxx','','')

3、window.opener - 打开页面2的原页面,可以在页面2中控制原页面

4、window.close(); - 关闭当前页面

5、window.setInterval('要执行的代码',执行的间隔时间-毫秒); - 重复的执行代码
6、window.setTimeout('要执行的代码',执行等待的时间-毫秒); - 等待一段时间再执行代码

它俩都可以用一个变量来接收,var a = window.setInterval('xxx',1000);
如果你想让它停,window.clearInterval(a);

7、window.navigate('url'); - 页面跳转
8、window.moveTo(x,y); - 将浏览器的位置定位
9、window.resizeTo(x, y); -先写!!!!!
10、window.scrollTo(x,y); - 很像锚点

二、window.history
window.history.back();

三、window.location
window.location.href - 当做值来使用,返回当前页面的地址

最重要的!:Document对象
1、id来取值 - document.getElementById('要取的ID'); - 返回的就是一个对象
3、class来取值 - document.getElementsByClassName('xxx'); -返回一堆对象

4、标记名来取值 - document.document.getElementsByTagName('xxx'); -返回一堆对象
2、name来取值 - document.getElementsByName('要取的name'); -返回一堆对象

innerHTML = '';如果赋值标记,那会把标记编译显示

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script type="text/javascript">
        window.onload = function () {
            window.open('Default2.aspx', '_blank', 'toolbar=no;menubar=no;status=no;width=100;height=100;resizable=no;location=no;');



        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>这是页面2</h1>
        <span id="aaa"><a href='http://www.baidu.com'>百度</a></span><br /><br />
        <span id="sss">点击这里</span>

        <script type="text/javascript">
            var sss = document.getElementById('sss');

            sss.onclick = function () {
                //1、将要变的元素取出来
                var aaa = document.getElementById('aaa');
                //2、改变内容
                //aaa.innerHTML = "<a href='http://www.baidu.com'>百度</a>";
                //aaa.innerText = "<a href='http://www.baidu.com'>百度</a>";

                //var bbb = aaa.innerText;
                //alert(bbb);

            };
        </script>

    </div>
    </form>
</body>
</html>

 

posted on 2016-07-28 12:32  爱意红沉  阅读(304)  评论(0编辑  收藏  举报