2008年9月14日 星期日

getElementByTagName

return an array with element with tag name, with order they appear in the page

ex: 
document.getElementByTagName("div")

innerHTML

the content of tag element
usage:  get or change the content of element
ex:
document.getElementById("test").innerHTML=  "change";

regular expression in javascript

syntax:
/  expression  /

. : match any character other than newline
\s:  match a whitespace character
\d:  match number
\w: match alphanumeric character 
^:  beginning of the string
$:  end of the string
\: escape character


quantifiers:
* :  o or more times
+:  1 or more times
?:  o or 1 time
{ n} :  n times
{min, max}:   
[abc]:  a or b or c


regular expression is a RegExp object
how to use:
ex:
var  key= /\d/;
if( key.test( "32") )
{
     alert("matched");
}

2008年8月27日 星期三

control logic ( if & switch)

switch , case, break , default:
the same as C syntax

if , else :
the same as C syntax

comment

single line: //

multiple lines: /* and */

2008年8月14日 星期四

prompt


let user enter data
ex:
prompt("what is your name",  "insert name here");


import javascript into html

<script type="text/javascript"  src="test.js"> </script>

body's event

onload:
when page is loaded

onresize:
when browser is resized

style object

each element of web page has a style object

style.height:

style.width:

document object

document.body.clientHeigth:
client window height

document.body.clientWidth:
client window width

document.getElementById("elementName")

document.cookie:
set cookie:
ex:
document.cookie="name1=peter;expires=1/1/2000;";

how to clear cookie:
set it value to "" & expiration data to -1

2008年6月12日 星期四

string method

indexOf()
find the pattern in the string
ex:
"abcdef".indexof("bc");

getElementById

getElementById
get html element 
ex:
html element:
input type="text", id="test",  name="abc"
javascript:
document.getElementById("test").value
access data from value

math methods

NaN:
not a number

parseInt():
convert test to integer
ex:
parseInt("1");

parseFloat()

isNaN():
ex:
var a=3;
isNaN(a);

toFixed():
ex:
a=3.333;
a.toFixed(2);
---> a=3.33

alert

show an alert box:
ex:
alert("hello");

variable , constant, function

variable:
ex:
var test=300;

constant:
ex:
const TEST= 300;


function:
ex:
function test() {

}


call two methods:
ex:
<body onload ="test(); test2();">