我已经尝试为我的Javascript类完成以下任务(我知道这是基本的)。但是,当我打开网页时,没有任何功能可以执行,我会丢失什么?我尝试查看其他示例,但似乎找不到我搞砸的内容。同样,也欢迎任何有助于将来代码问题的资源或良好的指导资源。任何帮助表示赞赏。
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WDV221 Intro Javascript</title>
<style>
div#container
{
width:960px;
margin:auto;
padding:10px;
background-color:white;
border:thin solid black;
}
</style>
<script>
var studentName = ""; //global variable to be used later
var studentEmail = ""; //global variable to be used later
function displayGreeting()
{
alert("Hello! Welcome to WDV221 Intro Javascript");
}
function getStudentName()
{
studentName = prompt("Please enter your name");
}
function getStudentEmail()
{
studentEmail = prompt("Please enter your e-mail address");
}
function printStudentInfo()
{
document.write("Student name:" + studentName + /n);
document.write("Student email:" + studentEmail + /n);
}
function displayEmail()
{
alert("Student Email: " + studentEmail);
}
function displayEmailName()
{
var atSymbol = 0; //local variable that will store the location of the @ symbol
//var emailNameOnly = ""; //local variable that will store the value of the name portion of the email address
studentEmail.indexOf("@");
var emailNameOnly = studentEmail.substr(0,atSymbol);
//alert( "Email name: " + studentEmail.substr(0,atSymbol) );
alert ("Email name: " + emailNameOnly);
}
function displayEmailServer()
{
var atSymbol = 0; //local variable that will store the location of the @ symbol
//var emailServerOnly = ""; //local variable that will store the value of the name portion of the email address
studentEmail.indexOf("@");
var emailServerOnly = studentEmail.substr(atSymbol + 1);
//alert( "Email name: " + studentEmail.substr(0,atSymbol) );
alert ("Email name: " + emailServerOnly);
}
</script>
</head>
<body>
<div id="container">
<h1>WDV221 Intro Javascript</h1>
<h2>Unit-3 Functions</h2>
<p>Tasks: </p>
<p>1. Run the displayGreeting( ) as a run time script. </p>
<script>
displayGreeting();
</script>
<p>2. Run the getStudentName( ) as a run time script.</p>
<script>
getStudentName();
</script>
<p>3. Write a function called getStudentEmail( ). The function should use the prompt( ) to ask the user to enter their DMACC Email address. Store the returned valued in the studentEmail variable that has already been defined.</p>
<p>4. Run the getStudentEmail( ) as a run time script.</p>
<script>
getStudentEmail();
</script>
<p>5. Write a function called displayEmail( ). The function will display the studentEmail variable with a message "Student Email:" in an alert. The button below will call the function when clicked.</p>
<p>
<input type="button" name="button" id="button" value="Display Email" onClick="displayEmail()">
</p>
<p>6. Complete the function called printStudentInfo( ). The function should write the studentName and studentEmail to the web page. Each in their own paragraph. </p>
<script>
printStudentInfo();
</script>
<p>7. Complete the displayEmailName( ). The function should display the name portion of the studentEmail variable. Do not include the @ symbol in the result. </p>
<p>Modify the following button to call the displayEmailName( ) with a click event handler.</p>
<p>
<input type="button" name="button2" id="button2" value="Display Email Name" onclick="displayEmailName()">
</p>
<p>8. Write a function called displayEmailServer( ). The function will display that portion of the studentEmail that follows the @ symbol. Do not include the @ symbol in the result.</p>
<p>9. Fix the button element that will run the displayEmailServer( ) with a click event handler.</p>
<p>
<input type="button" name="button3" id="button3" value="Display Email Server" onclick="displayEmailServer()">
</p>
<p> </p>
</div>
<h2> </h2>
</body>
</html>