我正在为学校编写一个程序,他希望我们执行以下操作:如果在“年龄”字段中输入了任何非数字条目,则会出现一个带有两行消息的警告框:
您输入的年龄只能包含数字。请重新输入。
Then : 如果输入的年龄小于 18 岁,则应在包含消息的按钮下方显示一个附加段落
然后:对于 18 岁及以上,脚本必须根据申请人获得的大学学位计算并显示薪水。如果申请人持有学位,那么工资将由申请人的年龄乘以 1000.00 美元来确定。如果没有学位,乘数将仅为 600.00 美元。当按下确定薪水按钮时,脚本将显示包含计算出的薪水报价的额外段落元素,如下面的示例插图所示。
我已经尝试了所有我能想到的方法来确保年龄字段中没有输入任何字母字符,但我似乎无法让它工作。请帮忙!
<?xml version='1.0' encoding='utf-8'?>
<!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' xml:lang='en' lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset= utf-8' />
<title>Form Based JavaScript</title>
<style type = "text/css">
h2 {text-align:left;}
body {background-color:lightblue;}
.input {font-family:"Courier New", Courier, monospace;}
</style>
<script type = "text/javascript">
<!--
function salary() `enter code here`
{
var age;
var degree;
if (age != [0-99]
{
document.writeln( "The age that you entered must contain only numerals. <br /> Please re-enter it.");
else if (age < 18)
document.writeln( " Sorry - you must be 18 or older for this job. <br /> Please reapply in [18 - age] years." );
else if (age >=18)
document.writeln( " You qualify! Salary offer [degree * ] dollars. See our staff for an application" );
}
}
// -->
</script>
<!-- project6.htm Tatiana Saavedra 04/17/2013 -->
</head>
<body>
<h2> Applicant Screening Page </h2>
<hr />
<form id = "myForm" action = "">
<p>Email:<input type = "email" id = "email"></p>
<p>Age:<input type = "number" maxlength="3" size="3" id = "age"></p>
<p><label>Check the box if you hold a college degree: <input type = "checkbox" id = "degree"></label></p>
<br />
<form action="">
<input type="button" value="Determine Salary" onclick="salary()"/>
</form>
</body>
</html>