課程
/前端開發(fā)
/JavaScript
/JavaScript入門篇
怎樣將一個文本框中用戶輸入的數(shù)字提出來進(jìn)行判斷?
比如<input type="text" ></input>里面的
2016-07-17
源自:JavaScript入門篇 1-8
正在回答
<!DOCTYPE html><html lang="en"><head> ? ?<meta charset="UTF-8"> ? ?<title>Title</title></head><body><form action="#"> ? ?<input id="score" type="number" value="70" name="score" max="100" min="0"> ? ?<button type="submit" onclick="myScore()">修改你的成績</button></form><script type="text/javascript"> function myScore() { ? ? ? var x = document.getElementById("score").value; ? ? ? if(x > 60) {alert("及格了不用挨屁屁了")} ? ? ? else {alert("你沒及格啊"); ? }</script></body></html>
用我這個試試吧 <!DOCTYPE?HTML> <html> <head> <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/> <title>判斷語句</title> ??<script?type="text/javascript"> var?score?=document.getElementById("score").value;?//score變量存儲成績,初值為80 ????function?getmessage(){ ??if(score>60) { ?????document.write("很棒,成績及格了。"); } ??else { ?document.write("加油,成績不及格。"); } ????} ??</script> </head> <body> <input?type="text"?id="score"/> <input?type="submit"?name="s"?value="提交"?onclick="getmessage()"/> </body> </html>
就是下面的代碼,火狐,IE,Opera都行不通,點了確認(rèn)就清空了而且沒有任何提醒
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標(biāo)題文檔</title><script language="javascript" type="text/javascript">? function check(){? var score=document.getElementById("tx").value;? if(score>=60){? alert("succeful");? <br/>? }else{? alert("fail");? }? }</script></head><br/><body><form>? <input name="" type="text" id="tx"/>? <input type="submit" name="button" id="button" value="提交" onclick="check()"/></form></body></html>
啊,不可能啊,我昨天用CHROME有反應(yīng)的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
<script language="javascript" type="text/javascript">
function check(){
var score=document.getElementById("tx").value;
if(score>=60){
alert("succeful");
}else{
alert("fail");
}
</script>
</head>
<body>
<form>
?<input name="" type="text" id="tx"/>
?<input type="submit" name="button" id="button" value="提交" onclick="check()"/>
</form>
</body>
</html>
實例代碼
營養(yǎng)米線 提問者
codechris 回復(fù) 營養(yǎng)米線 提問者
用ID 然后使用getElementById("id").value;
用var定義,然后用if ? ?else應(yīng)該就可以了
舉報
JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門
2 回答彈出的對話框里的文本輸入框是怎么來的
1 回答怎么運行不出來,判斷分?jǐn)?shù)。
2 回答如何控制文本框里面只能輸入數(shù)字?
1 回答如果用戶輸入一個漢字或者字母咋整? 如果用戶輸入一個比試卷總分還大的分?jǐn)?shù)咋整?
2 回答怎么實現(xiàn) 彈出一個輸入框,在輸入框中輸入指定內(nèi)容,否則就回到上一個alert
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-11-01
<!DOCTYPE html>
<html lang="en">
<head>
? ?<meta charset="UTF-8">
? ?<title>Title</title>
</head>
<body>
<form action="#">
? ?<input id="score" type="number" value="70" name="score" max="100" min="0">
? ?<button type="submit" onclick="myScore()">修改你的成績</button>
</form>
<script type="text/javascript">
function myScore() {
? ? ? var x = document.getElementById("score").value;
? ? ? if(x > 60) {alert("及格了不用挨屁屁了")}
? ? ? else {alert("你沒及格啊");
? }
</script>
</body>
</html>
2016-08-26
2016-07-18
就是下面的代碼,火狐,IE,Opera都行不通,點了確認(rèn)就清空了而且沒有任何提醒
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
<script language="javascript" type="text/javascript">
? function check(){
? var score=document.getElementById("tx").value;
? if(score>=60){
? alert("succeful");
? <br/>
? }else{
? alert("fail");
? }
? }
</script>
</head>
<br/>
<body>
<form>
? <input name="" type="text" id="tx"/>
? <input type="submit" name="button" id="button" value="提交" onclick="check()"/>
</form>
</body>
</html>
2016-07-18
啊,不可能啊,我昨天用CHROME有反應(yīng)的
2016-07-17
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
<script language="javascript" type="text/javascript">
function check(){
var score=document.getElementById("tx").value;
if(score>=60){
alert("succeful");
}else{
alert("fail");
}
}
</script>
</head>
<body>
<form>
?<input name="" type="text" id="tx"/>
?<input type="submit" name="button" id="button" value="提交" onclick="check()"/>
</form>
</body>
</html>
實例代碼
2016-07-17
用ID 然后使用getElementById("id").value;
2016-07-17
用var定義,然后用if ? ?else應(yīng)該就可以了