一、基本函数库

split():用于把一个字符串分割成字符串数组

toUpperCase():

substr():

长度

length()

拼接(两种)

+

concat():合并多个字符串,并返回合并的结果

查找

indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置

lastIndexOf():可返回一个指定的字符串值最后出现的位置,在一个字符串中的指定位置从后向前搜索

删除/添加

shift() :用于把数组的第一个元素从其中删除,并返回第一个元素的值

pop():用于删除并返回数组的最后一个元素

unshift() : 可向数组的开头添加一个或更多元素,并返回新的长度

push():可向数组的末尾添加一个或多个元素,并返回新的长度

截取

  substr(start,end):在字符串中抽取从 start 下标开始的指定数目的字符

简单例子:

<script type="text/javascript">
var str="i like php";
//拆分,把每个单词得到
var arr=str.split(" ");
//遍历数组,得到第一个字母,大写,放回原处
var word="";
var nstr="";
for(var k in arr){
word=arr[k][0].toUpperCase()+arr[k].substr(1);
nstr+=word+" ";
}
document.write(nstr);
</script>

检测浏览器是什么:

<script type="text/javascript">
if(navigator.userAgent.toLowerCase().indexOf("msie")>=0){
document.write("ie");
}else if(navigator.userAgent.toLowerCase().indexOf('firefox')>=0){
document.write("huohu");
}else if(navigator.userAgent.toLowerCase().indexOf('chrome')>=0){
document.write('google');
}
</script>

定时器的小例子(复习一些基础的函数):

Date()

setInterval()

getInterval()

toLocaleString()

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
<script type="text/javascript">
var i=0;
function fun1(){
D=new Date();
document.getElementById("div1").innerHTML=D.toLocaleString();
}
function fun2(){
window.clearInterval(t);
}
</script>
</head>
<body>
<div id="div1" style="border:1px solid red;"></div>
<input type="button" value="stop" onclick="fun2();"/>
</body>
</html>
<script type="text/javascript">
fun1();
var t=window.setInterval("fun1()",1000);
</script>

得到URL地址:

分析下面的URL:

            http://www.xxx:8080/test.php?user=admin&pwd=admin#login

    1. location.href:得到整个如上的完整url
    2. location.protocol:得到传输协议http:
    3. location.host:得到主机名连同端口www.xxx.cn:8080
    4. location.hostname:得到主机名www.xxx.cn
    5. location.pathname:得到主机后部分不包括问号?后部分的/test.php
    6. location.search:得到url中问号?之后井号#之前的部分?user=admin&pwd=admin
    7. location.hash:得到#之前的部分#login
<script type="text/javascript">
document.write("href:"+location.href+"<br/>");
//设置当前的主机名和端口号
document.write("host:"+location.host+"<br/>");
document.write("pathname:"+location.pathname+"<br/>");
document.write("search:"+location.search+"<br/>");
document.write("hash:"+location.hash+"<br/>");
location.replace("http://www.baidu.com");
</script>

js面向对象:http://www.dreamdu.com/javascript/define_object/

最新文章

  1. Visual Studio Code 配置指南
  2. tabs左右滚动
  3. PAT 1026. 程序运行时间(15)
  4. Ubuntu12.04安装JDK6
  5. CruiseControl.net
  6. java+hadoop+spark+hbase+scala+kafka+zookeeper配置环境变量记录备忘
  7. Apache-Tika解析XML文档
  8. ssh链接云主机的一些笔记
  9. Temporary ASP.NET Files 文件夹中保存的是什么内容?[转]
  10. 使用jquery控制display属性
  11. 返璞归真 asp.net mvc (3) - Controller/Action
  12. centos下安装最新版本git(通过master分支下载最新版)
  13. java的OutOfMemoryError: PermGen space实战剖析
  14. 解决jquery绑定click事件出现点击一次执行两次问题
  15. [Windows Azure] Windows Azure Storage &amp; SQL Database
  16. phpstudy composer 使用安装
  17. 常见的Javascript报错及解决方案
  18. Docker应用系列(一)| 构建Redis哨兵集群
  19. 使用JNDI连接数据库
  20. React第二篇:组件的生命周期

热门文章

  1. rest framework之渲染器
  2. 9、Python 连接 PostgreSQL数据库 -- psycopg2
  3. react 脚手架使用
  4. Windows 屏幕保护程序
  5. Vue学习笔记【9】——Vue指令之v-for和key属性
  6. 行业顶级NoSQL成员坐阵,NoSQL数据库专场重点解析!
  7. OpenSearch最新功能介绍
  8. webstorm使用说明
  9. nginx,php-fpm性能优化
  10. Jeecg 切换默认首页方法