Web effects date format, url extraction and decomposition, object code
A simple JS starter tutorial mainly includes the date format, URL extraction and decomposition, object operation, hope to help you.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>javascript Grammar </title>
<script type= "Text/javascript" >
<!--
var thisdate = new Date ();
/* Date Format * *
Document.writeln (Thisdate.tostring ());
Document.writeln ("<br/>");
document.write (Thisdate.getfullyear () + "-" + thisdate.getmonth () + "-" + thisdate.getday ());
Document.writeln ("");
Document.writeln (thisdate.gethours () + ":" + thisdate.getminutes () + ":" + thisdate.getseconds () + "." + Thisdate.getmilli Seconds ());
/*url Decomposition * *
document.write ("Set a URL with a parameter such as: FILE:///E:/DOCUMENTS%20AND%20SETTINGS/SIMON/%E6%A1%8C%E9%9D%A2/UNTITLED-1.HTML?AA=11&BB=CC
var url = document. Url.split ("?");
var param = url[1].split ("&");
for (i = 0; i < param.length; i++) {
var val = param[i].split ("=");
document.write (val[0] + "=" + val[1]);
document.write ("<br/>");
}
Open a new Document object
document.write ("document.write ("<input type= ' button ' value= ' New document ' onclick= ' newdocument ') '/>");
function NewDocument () {
Document.open ();
document.write ("New Document");
Window.settimeout (Window.close (), "3000");
}
The page loads the progress window, the page does not have the content to brush too quickly, may pass the onload control.
var placeHolder2 = Document.open (' untitled-2.html ', ' Test ', ' width=300,height=300 ');
JavaScript objects
/* Object
Properties can be defined within an object, such as Name,age, or outside the object, such as addr
Methods are defined in two ways, see definition of Say and Ageadd
*/
function person () {
this.name = ' AA ';
This.age = 12;
This.say = Sayperson;
This.ageadd=function () {
this.age++;
}
}
function Sayperson () {
Alert (THIS.name + "," + This.age + "," + this.addr);
}
function Newp () {
var p = new person ();
P.ADDR = "ABCD";
P.say ();
P.ageadd ();
P.say ();
}
Object 2 Simple custom object internal functions
function Chuman () {
function Sayhuman (attr) {
return human[attr];
}
var human = new Object ();
Human.username = "ABC";
Human.userage = 12;
Alert (Sayhuman ("Userage"));
Alert (Sayhuman ("UserName"));
}
Object 3
function Simon () {this.username; this.userage;}
Simon.prototype.userName = "";
Simon.prototype.setUserName = function (userName) {this.username = UserName;}
Simon.prototype.getUserName = function () {return this.username;}
Simon.prototype.setUserAge = function (userage) {this.userage = Userage;}
Simon.prototype.getUserAge = function () {return this.userage;}
function Csimon () {
var Simon = new Simon ();
Simon.setusername ("Simon hahah");
Simon.setuserage (22);
Alert (Simon.getusername () + "" + simon.getuserage ());
Use of the WITH (Simon) {//with
Alert (GetUserName () + "," + getuserage ());
}
var p, str = "";
For (p in Simon) {
STR +=p + "n";
}
alert (str);
}
Object 4
function CObj () {
function Obj () {this.username = "AA"; this.userage = 55;}
var obj = new obj ();
var p, str = "";
For (p in obj) {//for usage
str +=p + "=" + obj[p] + "n";
}
alert (str);
}
Object 5 Array Object
function Myarr () {
This.length = Arguments.length;
for (i = 0; i < this.length; i++) {
This[i] = arguments[i];
}
}
function Cmyarr () {
var Myarr = new Myarr ("ABC", 12, ' hello ', 3.5, true);
var str = "";
for (i = 0; i < myarr.length; i++) {
STR + + Myarr[i] + ",";
}
alert (str);
var p;
str = "";
For (p in Myarr) {
STR + + p + "=" + myarr[p] + "n";
}
alert (str);
}
Object 6 Array Object
function MyArr2 (size) {
This.length = size;
for (i = 0; i < this.length; i++) {
This[i] = "";
}
}
function cMyArr2 () {
var myArr2 = new MYARR2 (6);
Myarr2[0] = "AA";
MYARR2[1] = 3;
MYARR2[2] = ' DFADFA ';
MYARR2[3] = true;
MYARR2[5] = 0.4;
var p, str = "";
For (p in myArr2) {//for usage
str +=p + "=" + myarr2[p] + "n";
}
alert (str);
}
-->
</script>
<body onload= "Placeholder.close ();" >
<button value= "New person" onclick= "NEWP ()" >new person</button>
<button value= "New person" onclick= "Chuman ()" >new human</button>
<button value= "New person" onclick= "Csimon ()" >new simon</button>
<button value= "New person" onclick= "CObj ()" >new obj</button>
<button value= "New person" onclick= "Cmyarr ()" >new myarr</button>
<button value= "New person" onclick= "cMyArr2 ()" >new myarr2</button>
</body>