我自己在sublime中手寫代碼,對話框怎么就是彈跳不出來了?
<!DOCTYPE?html> <html> <head> <meta?charset="UTF-8"> <title>confirm確認對話框</title> <script> function?rec(){ var?mymessage=confirm("你是女生嗎?"); if(mymessage==true){ document.write("你是女生!"); } else{ document.write("你是男生!"); } } </script> </head> <body> <input?name="button"?type="button"??onClick="rec()"?value="點擊我,彈出確認對話框"> </body> </html>
2017-07-12
注意代碼中的分號,要用英文的,你用的中文的。改了就可以了。
var?mymessage=confirm("你是女生嗎?");
if(mymessage==true){
document.write("你是女生!");
}
else{
document.write("你是男生!");
}
2017-07-14
請注意調(diào)用函數(shù)的方法,沒加括號,還有id屬性記得加引號:<input type="button" value="點我變紅" onclick='toRed()' >
<input type="button" value="點我變綠" onclick='toGreen()'>
<input type="button" value="點我變黃" onclick='toYellow()'>
<div id="cont"></div>
2017-07-13
2017-07-13
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>函數(shù)傳參</title>
<style>
#cont{
width:300px;
height:300px;
background:gray;
}
</style>
<script>
function toRed()
{
var contid=document.getElementById('cont');
contid.style.background='red';
}
function toGreen()
{
var contid=document.getElementById('cont');
contid.style.background='green';
}
function toYellow()
{
var contid=document.getElementById('cont');
contid.style.background='yellow';
}
</script>
</head>
<body>
<input type="button" value="點我變紅" onclick='toRed' >
<input type="button" value="點我變綠" onclick='toGreen'>
<input type="button" value="點我變黃" onclick='toYellow'>
<div id=cont></div>
</body>
</html>
2017-07-12
真厲害!怎么看出來的?差別真的好小,中文的分號要細小點,英文的分號更加粗大一點;但是我在書上看的說分號不是必須,但是一種良好的編寫習慣建議加上;但沒想到,寫錯分號影響這么大,直接導致效果顯示不出來!