html(JS)学习笔记2
2016-03-15 21:22
441 查看
I/O
读取信息
var yourName = prompt(“What is your name?”);读入的是字符串,switch 用的是
===
onChange=”var dataEntered=document.getElementById(‘randInput’).value;
alert(‘User Typed ’ +dataEntered);”>
屏幕输出
document.write(“Random #(1-10) = “,Math.floor((Math.random()*10)+1),””);
document.getElementById(“sayHello”).innerHTML = “Hello” + yourName;
换行
<br/>
click
<a href="JavaScript:void(0)" onClick="alert('Hello');" ommouseover="this.style.color='red'" ommouseout="this.style.color='blue'" ommouseclick="this.text='You Double clicked me'" onmousedown="this.text='Don\'t Press too hard'" onmouseup="this.text='Thank you'">Say Hello</a><br/>
函数
argument对象:参变量个数不确定,模拟函数重载var sayHello=function(arg)
arguments.length返回个数注意加s
函数可以作为对象被new出来
var add=new Function(sum1,sum2);
call方法和
apply方法
变量是function scope
class
//example in textbook var obj={ property1: name,//comma } var obj={ name : "XiaoMing", age : 18,//comma!!! show : function(){ console.log(this.age); } };//semicolon!! obj.show(); //example in video var customer = { name:"Bob Tomas",adress:"123 Main",balance : 50.50}; for(k in customer){ document.write(customer[k]+'<br/>'); }
把对象set成一个constructor,给别人new
var obj=function (name,age){ this.name = name; this.age = age; this.show = function(){ console.log(this.age); }; }; obj.prototype.food = "an";//add elements var obj1=new obj("Mike",15); obj1.show();`
array
[1,2,3]
push(),
pop(),
shift()(删除第一项并缩小数组),
unshift(),
reverse(),
customer.sort(function(x,y){return y-x});
customer.splice(2,1,"P","pp");
toString()camel= =
delete customer
和python类似
string:
substr(beg,length) substring(beg,end+1)
//tags var strToStyle = "Random String"; document.write("Replace : ",strToStyle.replace("Random","explict")+"<br/>"); document.write("toUpperCase : ",strToStyle.toUpperCase(),"<br/>"); document.write("Big : ",strToStyle.big(),"<br/>"); document.write("Small : ",strToStyle.small(),"<br/>"); document.write("Bold : ",strToStyle.bold(),"<br/>"); document.write("Font Color : ",strToStyle.fontcolor("blue"),"<br/>"); document.write("Font Size : ",strToStyle.fontsize("8em"),"<br/>"); document.write("Italics : ",strToStyle.italics(),"<br/>"); document.write("Google : ",strToStyle.link("http://google.com"),"<br/>"); document.write("Sub : ",strToStyle.sub(),"<br/>"); document.write("Sup : ",strToStyle.sup(),"<br/>"); document.write("Strike : ",strToStyle.strike(),"<br/>");
Math
Math.PI.
Math.random;
P91
相关文章推荐
- jsp页面的数据获取方法
- [RxJS] Toggle A Stream On And Off With RxJS
- JS BOM
- js判断浏览器是否有滚动条
- extjs 组件与布局
- jsp登录界面(一)
- JavaScript 简介
- js中的toString
- JSTL 核心标签库
- JS对象继承方法
- javascript中为什么有时需要创建立即执行的函数
- js面向对象二--封装
- 玩转JavaScript正则表达式
- JSP and Servlet
- JavaScript高级程序设计(第三版)学习笔记22、24、25章
- fastjson 使用笔记
- JavaScript打印杨辉三角
- JavaScript子文本传到父文本框显示
- 通用JSON生成器3
- JavaScript节点属性