javascript 一些基礎

來源:互聯網
上載者:User

一些純程式碼

<html>
<head>
<title>學習Javascript</title>
<script type="text/javascript">
var clors=["red","green","blue"];
//alert(clors.toString());//輸出“red,green,blue”
//alert(clors.valueOf());//輸出“red,green,blue”
//alert(clors.toLocaleString());//輸出“red,green,blue”
document.write(clors.join("|"));//輸出“red|green|blue”
var sClors="red,green,blue";
var aClors=sClors.split(",");
document.write(typeof aClors);
document.write(aClors[0]);
var aClor=aClors[0].split("");
document.write("<br>"+aClor.toString());//輸出r,e,d

 

clors.sort();//排序
document.write("<br/>"+clors.toString());

var date1=new Date();
document.write("<br/>"+date1.toDateString());

eval("alert('hi')");

eval("function sayHi(){alert('hi');}");
sayHi();

function showColor(){
alert(this.color);
}
var oCar1=new Object;
oCar1.color="red";
oCar1.showColor=showColor;
oCar1.showColor();

//定義工廠函數
function createCar(){
var oTempCar=new Object;
oTempCar.color="blue";
oTempCar.doors=4;
oTempCar.mpg=23;
oTempCar.showColor=function(){
alert(this.color);
}//改成oTempCar.showColor=showColor;
return oTempCar;
}
var oCar1=createCar();
oCar1.showColor();

function sayHelloWorld()
{
alert("Hello World!");
}
setTimout(sayHelloWorld,10000);
</script>
</head>
<body>
<a href="javascript:goSomewhere(1,2,3,4)" onmouseover="window.status='Information on Wrox books.'">Books</a>//狀態列資訊
<a href="javascript:history.go(-1)">Back to the previous page</a>//前一頁,也可以用history.back(),後一頁history.forward()
</body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.