营养米线
2016-07-17 15:38
怎样将一个文本框中用户输入的数字提出来进行判断?
比如<input type="text" ></input>里面的
<!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都行不通,点了确认就清空了而且没有任何提醒
<!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>无标题文档</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有反应的
<!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>无标题文档</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>
实例代码
用ID 然后使用getElementById("id").value;
用var定义,然后用if else应该就可以了
JavaScript入门篇
739817 学习 · 9566 问题
相似问题