JavaScript For Beginners-Note
JavaScript For Beginners - The Code Project - JavaScript (cache)
A very good javascript tutorials for beginners.
Object: Function, Array, Date, RegExp
Regular expression methods:
search(), replace(), match(), split()
//傳回4, i表示忽略大小寫,
//如沒有找到傳回-1, search不支援全域g
"JavaScript".search(/script/i);
//忽略大小寫將text中所有的javascript
//全置換成Javascript
text.replace(/javascript/gi, "Javascript");
//回傳一個包含了比對結果的陣列,
//以下回傳["1","2","3"]
"1 plus 2 equals 3".match(/\d+/g)
Message box: alert, confirm, prompt
<script>
function ss(){
var ok=confirm('Click "OK" to go to yahoo, "CANCEL" to go to hotmail');
if (ok)
location="http://www.yahoo.com";
else
location="http://www.hotmail.com";
}
</script>
<body onload="ss();">
</body>
Form
<form name="aa">
<input type="text" size="10" name="bb">
<input type="button"value="Click Here" onclick="alert(document.aa.bb.value)">
</form>
Date methods:
getDate, getDay, getSeconds, getTime, getMonth,
getMinutes,getTimezoneOffset, getYear, getHours
windows attributes:
width, height, toolbar, location, directores, status, scrollbars, resizable, menubar
//open("URL","name","attributes")
<form>
<input type="button" value="Click"
onclick="window.open('page2.htm','win1','width=200,height=200')">
</form>
沒有留言:
張貼留言