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

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

我如何分離數(shù)字和字符串(初學(xué)者,JS)

我如何分離數(shù)字和字符串(初學(xué)者,JS)

慕婉清6462132 2023-11-12 15:02:43
我想知道為什么其他代碼不起作用我嘗試轉(zhuǎn)換為數(shù)字但仍然不起作用。** 圖片 1 圖片 2   function KareAlan() { var kare1 = document.getElementById("kare1")  .value; var kare1n = parseInt(kare1, 10) if (typeof kare1n == "number") {  kare1 = kare1 * kare1 * kare1;  document.getElementById("sonuc").innerHTML =   "Result:" + " " + kare1; } else if (typeof kare1n == "string") {  document.getElementById("sonuc").innerHTML =   "This procces is not possible,you should input at least one number"; }}
查看完整描述

3 回答

?
慕妹3242003

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊

我建議您閱讀更多有關(guān)html 表單的內(nèi)容:

function KareAlan() {

?var kare1 = document.getElementById("kare1").value;

?var kare1n = parseInt(kare1, 10)

?document.getElementById("sonuc").innerHTML =

? ?"Result:" + " " + kare1

}

<label for="kare1">Input Number</label><br>

<input type="number" value="5" id="kare1" oninput="KareAlan()"></input>

<h3 id="sonuc"></h3>



查看完整回答
反對 回復(fù) 2023-11-12
?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊

使用 !isNaN(number) 檢查數(shù)字。

我們使用 isNaN(),如果不是數(shù)字則返回 true,然后我們否定該語句以獲得一個(gè)如果它是數(shù)字則返回 true 的函數(shù)。


查看完整回答
反對 回復(fù) 2023-11-12
?
小唯快跑啊

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊

正如其他人指出的那樣,該值NaN是 a number。您需要在運(yùn)行代碼typeof之前進(jìn)行檢查,看看會(huì)發(fā)生什么parse


var theApple  = "Apple";

var theNumber = 1234;

console.log(

  "log line 1: " + theApple,

  parseInt(theApple, 10),

  "| typeof: " + typeof(theApple),

  "| typeof parsedInt: " + typeof(parseInt(theApple, 10)),


);


console.log(

  "log line 2: " + theNumber,

  parseInt(theNumber, 10),

  "| typeof: " + typeof(theNumber),

  "| typeof parsedInt: " + typeof(parseInt(theNumber, 10)),


);


// or simply


console.log("log line 3: ", !isNaN(theApple));

console.log("log line 4: ", !isNaN(theNumber));


// the problem with isNan is a value like this is also a NaN:

console.log("log line 5: ", !isNaN('0.0314E+2'));


查看完整回答
反對 回復(fù) 2023-11-12
  • 3 回答
  • 0 關(guān)注
  • 210 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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