第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么輸入后提示都的是default的值?。?/h1>
<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>switch</title>
<script?type="text/JavaScript">
function?day(){
var?myweek?=prompt("what?day?is?it?today?","1");
switch(myweek)
{
?case?1:
?case?2:
?document.write("學(xué)習(xí)理念知識(shí)");
?break;
?case?3:
?case?4:
?document.write("到企業(yè)實(shí)踐");
?break;
?case?5:
?document.write("總結(jié)經(jīng)驗(yàn)");
?break;
?case?6:
?case?7:
?document.write("周六、日休息和娛樂(lè)");
?break;
default:alert("input?error!");}
}
</script>
</head>
<body>
<input?type="button"?value="click?here!"?onClick="day()">
</body>
</html>


正在回答

3 回答

這里接收到的值是字符串,下面匹配的卻是整型,2種解決方法。

一,直接把接收到的值強(qiáng)制轉(zhuǎn)換為數(shù)字類(lèi)型,如:

var?myweek?=parseInt(prompt("what?day?is?it?today?","1"));

二,把下面所有case語(yǔ)句后面的值改為字符串,即加引號(hào),如:

switch(myweek)
????{
????????case?"1":
????????case?"2":
????????????document.write("學(xué)習(xí)理念知識(shí)");
????????????break;
????????case?"3":
????????case?"4":
????????????document.write("到企業(yè)實(shí)踐");
????????????break;
????????case?"5":
????????????document.write("總結(jié)經(jīng)驗(yàn)");
????????????break;
????????case?"6":
????????case?"7":
????????????document.write("周六、日休息和娛樂(lè)");
????????????break;
????????default:alert("input?error!");}
}


3 回復(fù) 有任何疑惑可以回復(fù)我~
#1

Bill0123 提問(wèn)者

非常感謝perona大大^_^
2015-08-14 回復(fù) 有任何疑惑可以回復(fù)我~
#2

Perona 回復(fù) Bill0123 提問(wèn)者

么么噠,不客氣~~
2015-08-14 回復(fù) 有任何疑惑可以回復(fù)我~
switch(parseInt(myweek))

這樣也可以

0 回復(fù) 有任何疑惑可以回復(fù)我~

var?myweek?=prompt("what?day?is?it?today?","1");

你的myweek獲取到的是一個(gè)字符串,把所有case都改成字符串

<!DOCTYPE?HTML>
<html>
<head>
	<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
	<title>switch</title>
	<script?type="text/JavaScript">
		function?day(){
		var?myweek?=prompt("what?day?is?it?today?","1");
		switch(myweek)
		{
		?case?"1":
		?case?"2":
		?document.write("學(xué)習(xí)理念知識(shí)");
		?break;
		?case?"3":
		?case?"4":
		?document.write("到企業(yè)實(shí)踐");
		?break;
		?case?"5":
		?document.write("總結(jié)經(jīng)驗(yàn)");
		?break;
		?case?"6":
		?case?"7":
		?document.write("周六、日休息和娛樂(lè)");
		?break;
		default:alert("input?error!");}
		}
	</script>
</head>
<body>
	<input?type="button"?value="click?here!"?onClick="day()"></body>
</html>


1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么輸入后提示都的是default的值???

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)