怎么讓在直接在表單上輸出年齡直接得出結(jié)果
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>if...else</title>
<style>
?.con{
? ? ?
? ? ?width:100px;
? ? ?high:20px;
?}
</style>
<script type="text/JavaScript">
function rec()
{?
?var myage ="rec";//趙紅的年齡為99
?myage=45;
if(myage<=44)
? { document.write("青年");}
else if(myage<=59)?
? {document.write("中年人");}
else if(myage<=89)
? {document.write("老年人");}
else? ? ?
? {document.write("長壽老年人");}}
</script>
</head>
<body>
? ? <input class="con" name="button" type="number" value=""/><br>
? ? ?<input name="button" type="button" onClick="rec()" value="請輸出你的年齡" />
</body>
</html>
2022-12-12
2019-11-08
在rec()方法中定義了常量【myage=45;】的話,那么調(diào)用rec()方法時就一直取的45這個常量。
重點:我們需要獲取從文本框中用戶輸入的值,動態(tài)判斷:
獲取表單的實現(xiàn)代碼:var myage = document.getElementById("age").value;
參考代碼:
2019-11-06
怎么讓他在表單里直接輸入年齡后顯示