javascriptone
var start=Date.now();
document.write("<h1>This is a paragraph.</h1>");
function myFunction()
{
x=document.getElementById("demo");
x.innerHTML="Hello JavaScript! by id";
}
function myFun()
{
x=document.getElementsByClassName("demo");
x[0].innerHTML="Hello JavaScript! by class";
}
function changeImg()
{
x=document.getElementById('lamp');
if(x.src.match("../resources/img/on.gif")){
x.src="../resources/img/off.gif";}
else{
x.src="../resources/img/on.gif";
}
}
function red(){
x=document.getElementById('red');
x.style.color="#ff0000";
}
function submit(){
x=document.getElementById('num').value;
if(x==""||isNaN(x)){
alert("not number");
}else{
alert("is number");
}
}
document.write("Hello \
world!");
var x=2;
var y=x+3;
var z="Yes,I am!"
document.write(x,y,z);
var w=123e5,q=123e-5;
document.write(w+q);
var cars=new Array();
cars[0]="aaa";
cars[1]="bbb";
document.write(cars[1]);
var doors=new Array("ccc","ddd","eee");
document.write(doors[2]);
var wood=["fff","gggg","hhh"];
document.write(wood[0]); //b,e,f
var person={
first:"Bill",
last:"Gates",
age:"12"
}
var x;
var txt="";
document.write("<br/>"+person.first+"<br/>");
document.write(person["last"]+"<br/>");
for(x in person){
txt+=person[x];
}
document.write(txt);
myName=new Object();
myName.first="li";
myName.last="jin";
myName.age=19;
document.write("<br/>"+myName.first+" is "+myName.age+" years old. jin的字符串长度是"+myName.last.length+"转换成大写"+myName.first.toUpperCase()+myName.last.toUpperCase());
function add(name,job){
alert("Welcome "+name+" ,the "+job);
}
function cat(a,b){
return a*b;
}
document.getElementById("logic").innerHTML=cat(3,5);
var txt1="<br/>What a very"
var txt2="nice day!"
var txt3=txt1+" "+txt2;
document.write(txt3);
x=5+5;
document.write(x);
document.write("<br />"); //10
x="5"+"5";
document.write(x);
document.write("<br />"); //55
x=5+"5";
document.write(x);
document.write("<br />");//55
x="5"+5;
document.write(x);
document.write("<br />");//55
//星期几
function week(){
var x;
var d=new Date().getDay();
switch(d){
case 0:x="Today is Sunday.";break;
case 1:x="Today is Mon.";break;
case 2:x="Today is Tues.";break;
case 3:x="Today is Wed.";break;
case 4:x="Today is Thur.";break;
case 5:x="Today is Fri.";break;
case 6:x="Today is Sat.";break;
}
document.getElementById('weeks').innerHTML=x;
}
cars=["BWM","VOLVE","SAAB","FORD"];
var i=0;
while(cars[i]){
document.write(cars[i]);
i++;
}
document.write("<br/>");
var j=0;
for(;cars[j];){
document.write(cars[j]);
j++;
}
function some(){
try{
adddlert("Welcome guest!");
}
catch(a){
txt="页面有一个错误\n\n"+"错误描述:"+a.message+"\n\n"+"点击继续。"
alert(txt);
}
}
function test(){
try{
var x=document.getElementById('write').value;
if(x=="") throw "值为空";
if (isNaN(x)) throw "不是数字";
if (x>10) throw "太大";
if(x<5) throw "太小";
}
catch(err){
var y=document.getElementById('test');
y.innerHTML="错误:"+err+"。";
}
}
//表单验证 必填(或必选)项目
function validate_required(field,alerttxt){
with(field)
{
if(value==null||value==""){
alert(alerttxt);
return false;
}
else{
return true;
}
}
}
function validate_form(thisform){
with(thisform){
if(validate_required(email,"Email must be filled out!")==false){
email.focus();
return false;
}
}
}
//邮箱验证
function validate_emaile(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false}
else {return true}
}
}
function validate_forme(thisform)
{
with (thisform)
{
if (validate_emaile(email,"Not a valid e-mail address!")==false)
{email.focus();return false}
}
}
//DOM
var x=document.getElementById("main");
var y=x.getElementsByTagName('p');
document.write(y[0].innerHTML);
y[1].innerHTML="改变了内容哦"
//日期
document.write("<br/>今天的日期是:"+Date());
//css
document.getElementById('p2').style.color="red";
function change(id){
id.innerHTML="欢迎!"
}
document.getElementById('foc').onclick=function(){displayDate()};
function displayDate(){
document.getElementById('em').innerHTML=Date();
}
function aler(){
alert("欢迎进入(^.^)");
}
var message = "some String";
document.write(typeof bcd);
document.write(typeof message);
document.write(typeof(null));
document.write(typeof 32);
// var color='blue';
// function changeColor(){
// if (color==='blue') {
// color="red";
// }else{
// color='red';
// };
// }
// changeColor();
// document.write("<br/>"+color);
var color="blue";
function changeColor(){
var anotherColor="red";
function swapColor(){
var tempColor= anotherColor;
anotherColor =color;
color=tempColor;
alert(color);
}
swapColor();
}
changeColor();
var personsb={
name: "koooh",
age: 12,
5:true
}
document.write("<p>"+personsb["name"]+"</p>");
document.write("<p>"+personsb.name+"</p>");
document.write("<p>"+personsb[5]+"</p>");
//数组Array
var computers=new Array(3);
var pointer=new Array("poin1","poin2","poin3");
var clothes=["red","green","blue"];
document.write("<p>"+clothes+"</p>");
document.write("<p>"+clothes.toString()+"</p>");
document.write("<p>"+clothes.valueOf()+"</p>");
document.write("<p>"+clothes.join("&&")+"</p>");
clothes[clothes.length]="black";
document.write("<p>"+clothes[3]+"</p>");
if(Array.isArray(clothes)){
document.write("hello!");
}
var person1={
toLocaleString:function(){
return "Niko";
},
toString:function(){
return "Mimo";
}
}
var person2={
toLocaleString:function(){
return "Niko2";
},
toString:function(){
return "Mimo2";
}
}
var people=[person1,person2];
document.write("<p>"+people+"</p>"); //默认字符串转换为toString()
document.write("<p>"+people.toString()+"</p>");
document.write("<p>"+people.toLocaleString()+"</p>");
var someColors=new Array();
var count=someColors.push("red","green");
document.write("<p>"+count+"</p>"); //2
document.write("<p>"+someColors+"</p>"); //red,green
count=someColors.push("black");
document.write("<p>"+count+"</p>"); //3
document.write("<p>"+someColors+"</p>"); //red,green,black
count=someColors.pop();
document.write("<p>"+count+"</p>"); //black !important
document.write("<p>"+someColors+"</p>"); //red,green
count = someColors.shift();
document.write("<p>"+count+"</p>"); //red
document.write("<p>"+someColors+"</p>"); //green
count=someColors.unshift("yellow","pink");
document.write("<p>"+count+"</p>"); //3
document.write("<p>"+someColors+"</p>"); //yellow,pink,green
var num=[1,2,3,4,5,23,10,13,23];
document.write("<p>"+num+"</p>");
document.write("<p>"+num.reverse()+"</p>"); //顺序反传
document.write("<p>"+num.sort()+"</p>"); //字符串从小到大,并不是数字从小到大
function compares(a,b){
if(a<b){
return 1; //比较函数第一个应该位于第二个之后的返回1
}
if(a>b){
return -1;
}
else{
return 0;
}
};
num.sort(compares)
document.write("<p>"+num+"</p>");
function cp(a,b){
return a-b;
}
num.sort(cp) //concat 和 slice不会改变原始数组
document.write("<p>"+num+"</p>");
var dogs=["dots","white"];
var dogs2=dogs.concat("yellow","brown","black");
document.write("<p>"+dogs+"</p>"); //dots,white
document.write("<p>"+dogs2+"</p>"); //dots,white,yellow,brown,black
var dogs3=dogs2.slice(1);
var dogs4=dogs2.slice(1,3);
document.write("<p>"+dogs3+"</p>"); //white,yellow,brown,black
document.write("<p>"+dogs4+"</p>"); //white,yellow
var numbers=[1,2,3,4,5,4,3,2,1];
var everyResult=numbers.every(function(item){
return(item>2);
})
document.write("<p>"+everyResult+"</p>");//false
var someResult=numbers.some(function(item,index,array){
return(item>2);
})
document.write("<p>"+someResult+"</p>");//true
var filterResult=numbers.filter(function(item,index,array){
return(item>2);
})
document.write("<p>"+filterResult+"</p>");//3,4,5,4,3
var mapResult=numbers.map(function(item,index,array){
return(item>2);
})
document.write("<p>"+mapResult+"</p>");//false,false,true,true,true,true,true,false,false
var mapResult=numbers.map(function(item,index,array){
return(item*2);
})
document.write("<p>"+mapResult+"</p>");//2,4,6,8,10,8,6,4,2
numbers.forEach(function(item,index,array){
document.write(item*2);//2468108642 forEach无返回值
})
var values=[1,2,3,4,5,6];
var sum=values.reduce(
function(prev,cur,index,array){
return prev+cur;
})
document.write("<p>"+sum+"</p>");
var sumr=values.reduceRight(
function(prev,cur,index,array){
return prev+cur;
})
document.write("<p>"+sumr+"</p>");
//Date
var stop=Date.now();
var time=stop-start;
document.write("<p>"+time+"</p>");
//正则表达式
var text = "000-00-0000";
var pattern = /\d{3}-\d{2}-\d{4}/;
if(pattern.test(text)){
document.write("正则表达式哦")
}
var sumi=function(num1,num2){
return num1+num2;
}
document.write(sumi(1,3));
function suma(num1){
return num1+10;
}
function addadd(a,b){
return a(b);
}
var book=addadd(suma,20);
document.write(book);
//高端函数
function createComparisonFunction(propertyName){
return function(object1,object2){
var value11=object1[propertyName];
var value22=object2[propertyName];
if(value11<value22){
return -1;
//return value11-value22;
}else if(value11>value22){
return 1;
}
else{
return 0;
}
};
}
var data = [{name:"zhang",age:12},{name:"li",age:14}];
data.sort(createComparisonFunction("name"));
document.write(data[0].name);
data.sort(createComparisonFunction("age"));
document.write(data[0].age);
//阶乘函数
function back(num){
if(num<=1){
return num;
}else{
return num*back(num-1);
}
}
document.write("<p>5的阶乘是"+back(5)+"</p>");
function back(num){
if(num<=1){
return num;
}else{
return num*arguments.callee(num-1);
}
}
document.write("<p>5的阶乘是"+back(5)+"</p>");
window.page="red";
var o = {page:"blue"};
function sayPage(){
document.write(this.page);
}
sayPage();//red
o.sayPage=sayPage;
o.sayPage();//blue
function outer(){
inner();
}
function inner(){
document.write("<p>"+inner.caller+"</p>");
document.write("<p>"+arguments.callee.caller+"</p>");
}
outer();
//apply
function summ(num1,num2){
return num1+num2;
}
function callSum1(num1,num2){
return summ.apply(this,arguments)
}
function callSum2(num1,num2){
return summ.apply(this,[num1,num2]); //20
//return summ(num1,num2); //20
}
document.write(callSum1(10,10));
document.write(callSum2(10,10));
//call
window.page="red";
var o = {page:"blue"};
function sayPage(){
document.write(this.page);
}
sayPage();//red
sayPage.call(this); //red
sayPage.call(window); //red
sayPage.call(o); //blue
// var pages=sayPage.call(o);
// pages(); //blue
var pages=sayPage.bind(o);
pages(); //blue
//基本包装类型
var s1="some text";
var s2=s1.substring(2);
s1=null;
document.write("<p>"+s1+"</p>"); //some text
document.write("<p>"+s2+"</p>"); //me text
var obj=new Object("some text");
document.write("<p>"+obj+"</p>"); //some text
document.write(obj instanceof String); //true
var look="25";
var looks=Number(look); //数字 25 Number为转型函数
document.write("<p>"+typeof looks+"</p>"); //number
//区分
var looks2=new Number(look); //构造了新函数
document.write("<p>"+typeof looks2+"</p>"); //object
javascriptone的更多相关文章
- Javascript-one
今天,学习Javascript第一天,学习了一些基本的概念,下面就对今天所学的知识进行一个整理,回顾吧! 首先,将Javascript代码包含在(X)html文档中,主要的方法是使用<scrip ...
随机推荐
- [OC笔记]@property之个人理解,大神轻拍
/** * 一个简单的对象 * * @author suzhen * */ public class SimpleObjcet { /** * 声明一个age字段 */ private Object ...
- Appium移动自动化测试之安装Android SDK和JDK
安装好Appium后,我们来继续安装Android SDK和JDK,JDK的安装以及环境变量配置这边就不再多说了,毕竟都是从事自动化的,这个应该是so easy.闲言少续,我们来操作Android S ...
- qt5中QPrinter的使用兼容性问题
qt5与qt4在QPrinter中使用的不同点如下: 在.pro文件中加入如下语句:
- fastjson将json字符串转化成bean对象解析出错的检查方法
我的情况是:解析第一层数据成功,解析第二层嵌套的数据失败.如: { "response": { "resultcode": "0", &qu ...
- Brocade博科光纤交换机zone配置
1.规划 交换机 端口 用途 DS6520B-A 94 存储模块1-1 95 存储模块2-1 68 DB1网卡1-1 69 DB2网卡1-1 DS6520B-B 94 存储模块1-2 95 存储模块2 ...
- (转)oracle中用户删除不了,ORA-01940提示 “无法删除当前已连接用户”
Oracle删除用户的提示无法删除当前已连接用户两种解决方法如下: 1.先锁定用户.然后查询进程号,最后删除对应的进程.在删除对应的用户 SQLalter user XXX account lock; ...
- java多线程详解(3)-线程的互斥与同步
前言:前一篇文章主要描述了多线程中访成员变量与局部变量问题,我们知道访成员变量有线程安全问题,在多线程程序中 我们可以通过使用synchronized关键字完成线程的同步,能够解决部分线程安全问题 在 ...
- 笔记本win8,mac10.10,ubuntu,android四系统安装
前言,最简单的是win8和ubuntu 最难啃的是mac android版只是要注意一个小技巧,目前算是独创 (被android坑了一次,两块硬件,android版把500Gntfs的硬盘整个识别为一 ...
- 加载音频Audio
var cameraAudio = new Audio(); cameraAudio.src = 'camera.wav'; // 设置音频对象的属性,预加载视频 var options_audio ...
- Linux 条件判断
1. 按照文件类型判断 -b 文件 #判断文件是否存在,并且是设备文件 -c 文件 #判断文件是否存在,并且是字符设备文件 -d 目录 #判断目录是否存在,并且是否为目录(是目录返回真) -e 文件 ...