Web之一 JS
来源:互联网 发布:学拼音打字软件下载 编辑:程序博客网 时间:2024/05/16 11:02
1.js各种弹窗
1).alertalert("hello");2).confirmif(confirm("how are you?") == true){document.write("好");}else{document.write("不好");}3).promptvar scope = prompt("请输入你的成绩","100");alert("我的成绩是: " + "scope");
2.打开、关闭窗口
var win = window.open(url); win.close();
3.事件
1)onclick 鼠标点击事件<input type="button" onclick="message()">2)onmouseover 鼠标经过事件<input type="button" onmouseover="message()">3)onmouseout 鼠标移开事件<input type="button" onmouseout="message()">4)onfocus 光标聚焦事件<input type="button" onfocus="message()">5)onblur 失焦事件<input type="button" onblur="message()">5)onselect 选中事件<textarea onselect="message()">hello!</textarea>5)onchange 内容改变事件<input type="text" onchange="message()">5)onload 加载事件<body onload="message()"> 欢迎学习JavaScript。</body>5)onunload 卸载事件<body onunload="message()"> 欢迎学习JavaScript。</body>
4.内置对象
4.1 String对象
var str = "Hello World";//全部大写str.toUpperCase();//全部小写str.toLowerCase();//返回指定位置的字符str.charAt(2);//返回字符串首次出现的位置,下面为o第二次出现的位置,第二个参数为开始索引的位置str.indexOf("o",str.indexOf("o")+1);//切割str.split(";");//截取字符串str.substring(startPos,endPos);str.substr(startPos,length);
4.2 Math对象
//PI常量Math.PI;//向上取整Math.ceil(6.3);//7//向下取整Math.floor(6.3);//6//四舍五入Math.round(6.3);//随机数 0~1Math.random();
4.3 数组对象
//定义数组var arr = new Array();var arr = [1,2,3];//数组连接arr1.concat(arr2,arr3);//指定分隔符连接数组arr.join(";");//数组排序arr.sort();//颠倒数组元素顺序arr.reverse();//从已有数组里返回选定的数组arr.slice(start,end);//从数组中删除或新增元素arr.splice(start,delNum,item1,item2)
4.4 Date对象
//新建对象var mydate = new Date();//年 mydate.getFullYear();mydate.setFullYesr(2016);//月 0~11mydate.getMonth();mydate.setMonth(0);//天1~31mydate.getDate();mydate.setDate(20);//小时 0~23mydate.getHours();//分 0~59mydate.getMinutes();//秒 0~59mydate.getSeconds();//星期 1~7mydate.getDay();mydate.setDay(1);
5.浏览器对象(window对象)
5.1 setInterval() setTimeout() 延时器
//setInterval() clearInterval() function clock(){ var time=new Date(); document.getElementById("clock").value = time; } var tt = setInterval(clock,1000); <input type="button" value="Stop" onclick="clearInterval(tt)"/>
5.2 history()
//返回上一个页面window.history.back();window.history.go(-1);//返回下一个页面window.history.forward();window.history.go(1);//返回当前页面之后浏览过的第三个历史页面window.history.go(3);
5.3 location()
//urlwindow.location.href//锚点window.location.hash//主机名和端口号window.location.host//主机名window.location.hostname//端口号window.location.post
6.DOM对象
5.1 获取元素
//根据id取元素document.getElementById("id");//根据name取元素document.getElementsByName("name");//根据标签名称去元素,如p、a等document.getElementsByTagName("tagName");
5.2 节点
//getAttribute() 根据节点的属性名称获取属性值 var node = document.getElementById("id");var title = node.getAttribute("title");//setAttribute() 设置属性值node.setAttribute("title","WEB前端技术");//节点的属性var nodes = document.getElementsByTagName("li");for(var i=0; i<nodes.length; i++){documents.write(nodes[i].nodeName); //LIdocuments.write(nodes[i].nodeValue); //nulldocuments.write(nodes[i].nodeType); //1}//创建节点document.createElement(tagName);//子节点var childNodes = node.childNodes;//子节点的第一项和最后一项node.firstChild;node.lastChild;//父节点node.parentNode;//兄弟节点node.nextSibling;node.previousSibling; //添加节点 appendChild()var otest = document.getElementById("test"); var newnode = document.createElement("li");newnode.innerHTML = "PHP";otest.appendChild(newnode);//插入节点 insertBefore()parantNode.insertBefore(newNode,node);//删除节点node.removeChild(node);//替换节点node.replaceChild (newnode,oldnode);//创建文本节点 createTextNode()var pNode = document.createElement("p"); var text = document.createTextNode("I love JavaScript!"); pNode.appendChild(text); document.body.appendChild(pNode);
0 0
- Web之一 JS
- 指尖下的js ——多触式web前端开发之一:对于Touch的处理
- 指尖下的js ——多触式web前端开发之一:对于Touch的处理
- 指尖下的js ——多触式web前端开发之一:对于Touch的处理
- 指尖下的js ——多触式web前端开发之一:对于Touch的处理
- [转]指尖下的js ——多触式web前端开发之一:对于Touch的处理
- 指尖下的js ——多触式web前端开发之一:对于Touch的处理
- Web services cache 之一
- Web编程之一 urlparse
- Java Web之一 JQuery
- web前端-之一
- Java web之一
- js笔记之一
- js综合案例之一
- JS面试题之一
- js正则表达式之一
- 初探js之一
- WEB-js
- 自定义的View 重写UIView的方法
- ZOJ 2966 Build The Electric System(最小生成树)
- redis单机搭建--详细
- 2、Maven在MyEclipse的集成,并建立一个简单的Maven项目
- BZOJ-2875 随机数生成器 矩阵乘法快速幂+快速乘
- Web之一 JS
- poj 3255 Roadblocks(次最短路径)
- Theano 学习笔记 Basics:Baby Steps - Algebra
- thinkphp源码解析 (Version 3.1) -4 /Lib/Core/Dispatcher.class
- jq开发插件格式
- sql笔记-postgreSQL
- 前段js滑动到最底端触发加载下一页的方法
- Check list
- 使用apktool 2.0 反编译和批量打包