為什么定義函數(shù)名改成open時,結(jié)果就沒有用。是因為函數(shù)名有限制么?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>window對象</title>
<script type="text/javascript">
function open()
?{
? ? ?var bb=confirm("歡迎來到慕課網(wǎng)");
? ? ? ?if(bb==true)
? ? ? ? {window.open("http://idcbgp.cn","width=600px,height=400px" ? ? ? ? ? ? ? ?);
? ? ? ? }
? ? else?
? ? {return;}
? ? }
</script>
</head>
<body>
<form>
<input type="button" value="點擊我,打開新窗口" onclick="open()" />
</form>
</body>
</html>
2016-11-30
嚴(yán)格意義上講,open已經(jīng)算是javascript定義過的詞了,所以我們是不能用來做變量名或者方法名噠,具體可以查閱一下js的關(guān)鍵字和保留字。(break、case、catch、continue、default、delete、do、else、finally、for、function、if、in、instanceof、new、return、switch、this、throw、try、typeof、var、void、while、with
、abstract、boolean、byte、char、class、const、debugger、double、enum、export、extends、fimal、float、goto、implements、import、int、interface、long、mative、package、private、protected、public、short、static、super、synchronized、throws、transient、volatile)都不能用來命名,你在open后面加個數(shù)字就可以了
2016-11-30
因為open在JavaScript中是一個關(guān)鍵字?