亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

哪里錯了?

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>confirm</title>

? ? ?

? <script type="text/javascript">

? function rec(){? ? //函數

? ? var mymessage=confirm("你是男士?");//變量加上消息對話框

? ? if(mymessage==true)? //if和else是判斷語句

? ? {

? ? document.write("你是女士!");

? ? }

? ? else

? ??

? ? ? ? document.write("你是男士!");

? ? }

? ? </script>

? ?

? ?<script type="text/javascript">

? ? ? ?function asd()

? ? ? ? ? ?var ddd=confirm("你喜歡周杰倫嗎")

? ? ? ?if(asd==true){

? ? ? ? ? document.write("喜歡,他的歌超級好聽")

? ? ? ? ?};

? ? ? ? else

? ? ? ? ? ? {document.write("不喜歡,你沒有品味");

? ? ? ? }?

? ? ? ?

? ? ? </script>

? ?

? ?

? ?

</head>

<body>

? ? <input meme="button" type="button" onClick="rec()" value="點擊我,彈出確認對話框" />

? ? <input name="buttom" type="bottom" onClick="asd()" value="點喜歡,點喜歡"/>

</body>

</html>


正在回答

2 回答

其實你把你現在的代碼復制到VScode里面,問題就顯而易見了!

第一:

http://img1.sycdn.imooc.com//625ecd460001634b04880267.jpg

創建函數的時候要有大括號!大括號!大括號!這個很重要!

再把后面的內容放進打括號里面,這個意思就是:當點擊按鈕時,執行asd()里面的代碼,不點擊就不執行!

第二:

http://img1.sycdn.imooc.com//625eca170001df1b04140278.jpg

if else條件語句不需要分號,接著后面寫即可;

第三:

http://img1.sycdn.imooc.com//625eca830001388008250105.jpg

input元素的類型只有button,沒有bottom,按鈕的英語單詞是button哦(個人寫按鈕喜歡直接這樣寫->? ?<button>點擊我,彈出確認對話框</button>)

第四:

http://img1.sycdn.imooc.com//625eceda0001f39d04220259.jpg

if語句里的條件時你創建的變量 bbb 是否為真 不是函數!所以這里應該這樣寫 if (ddd == true) {...} else{...};

還有寫代碼的時候記得注意語句的邏輯哦!當confirm類容為真時,返回true,但是你看看根據你的意思是:你是女士?為真時 輸出 你是女士。


我個人比較喜歡把js寫在body之后:

<body>

? <input meme="button" type="button" onClick="rec()" value="點擊我,彈出確認對話框" />

? <!-- <input name="buttom" type="bottom" onClick="asd()" value="點喜歡,點喜歡" /> -->

? <button onclick="asd()">點喜歡,點喜歡</button>

</body>


<script type="text/javascript">


? function rec() {

? ? var mymessage = confirm("你是男士?");//變量加上消息對話框

? ? if (mymessage == true) ?//if和else是判斷語句,當mymessage為真時輸出

? ? {

? ? ? document.write("你是男士!");

? ? }

//否則輸出

? ? else {

? ? ? document.write("你是女士 ?!");

? ? };

? } ; //函數


</script>




<script type="text/javascript">


? function asd() {

? ? var ddd = confirm("你喜歡周杰倫嗎");

? ? if (ddd == true) {

? ? ? document.write("喜歡,他的歌超級好聽");

? ? }

? ? else {

? ? ? document.write("不喜歡,你沒有品味");

? ? }

? };

</script>


//其實這兩個函數可以寫在一個script標簽里!


0 回復 有任何疑惑可以回復我~

<html>


<head>

? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

? ? <title>confirm</title>

? ? <script type="text/javascript">

? ? ? ? function rec() { ? ?//函數

? ? ? ? ? ? var mymessage = confirm("你是男士?");//變量加上消息對話框

? ? ? ? ? ? if (mymessage == true) ?//if和else是判斷語句

? ? ? ? ? ? //當 mymessage 為真,則頁面輸出你是男士

? ? ? ? ? ? {

? ? ? ? ? ? ? ? document.write("你是男士!");

? ? ? ? ? ? }

? ? ? ? ? ? //否則,則頁面輸出你是女士

? ? ? ? ? ? //輸出的順序錯了

? ? ? ? ? ? else {

? ? ? ? ? ? ? ? document.write("你是女士!");

? ? ? ? ? ? }

? ? ? ? }


? ? ? ? function asd() {

? ? ? ? ? ? var ddd = confirm("你喜歡周杰倫嗎")

? ? ? ? ? ? // if中判斷條件應該用變量而不是方法

? ? ? ? ? ? if (ddd == true) {

? ? ? ? ? ? ? ? document.write("喜歡,他的歌超級好聽")

? ? ? ? ? ? }

? ? ? ? ? ? else {

? ? ? ? ? ? ? ? document.write("不喜歡,你沒有品味");

? ? ? ? ? ? }

? ? ? ? }

? ? </script>

</head>

<body>

? ? <input meme="button" type="button" onClick="rec()" value="點擊我,彈出確認對話框" />

? ? <!-- input的type沒有buttom, type值應為button -->

? ? <input name="button" type="button" onClick="asd()" value="點喜歡,點喜歡" />

</body>

</html>


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
JavaScript入門篇
  • 參與學習       741182    人
  • 解答問題       9865    個

JavaScript做為一名Web工程師的必備技術,本教程讓您快速入門

進入課程

哪里錯了?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號