我正在尝试使函数验证电子邮件地址,并从html输入的表单标签中获取所有输入。我正在尝试在新窗口中创建简历。即输入姓名,地址,职业目标等。
我使用不同的方法从事此功能已经有一段时间了。
//html
<!DOCTYPE html>
<html>
<head>
<title>Web 115 Final Project</title>
</head>
<body>
<script src="projectJS.js"></script>
<form id = "myForm">
<label for="name">Enter Your Full Name</label><br>
<input type = "text" id="name" ><br><br>
<label for="address">Enter Your Address</label><br>
<input type = "text" id="address" ><br><br>
<label for="phone">Enter Your Phone Number</label><br>
<input type = "text" id="phone" ><br><br>
<label for="email">Enter Your Email Address</label><br>
<input type = "text" id="email" ><br><br>
<label for="objectives">Enter Your Career Objectives</label><br>
<textarea rows="4" cols="50" id="objectives"></textarea><br><br>
<label for="personalInfo">Enter Your Personal Information</label><br>
<textarea rows="4" cols="50" id="personalInfo"></textarea><br><br>
<label for="education">Enter Your Educational Background</label><br>
<textarea rows="4" cols="50" id="education"></textarea><br><br>
<label for="employment1">Enter Your Most Recent Employment Start/End Date</label><br>
<input type="date" id="employment1"><br><br>
<label for="description1">Describe This Employment Experience</label><br>
<textarea rows="4" cols="50" id="description1"></textarea><br><br>
<label for="employment2">Enter Your Second Most Recent Employment Start/End Date</label><br>
<input type="date" id="employment2"><br><br>
<label for="description2">Describe This Employment Experience</label><br>
<textarea rows="4" cols="50" id="description2"></textarea><br><br>
<label for="employment3">Enter Your Third Most Recent Employment Start/End Date</label><br>
<input type="date" id="employment3"><br><br>
<label for="description3">Describe This Employment Experience</label><br>
<textarea rows="4" cols="50" id="description3"></textarea><br><br>
<label for="employment4">Enter Your Forth Most Recent Employment Start/End Date</label><br>
<input type="date" id="employment4"><br><br>
<label for="description4">Describe This Employment Experience</label><br>
<textarea rows="4" cols="50" id="description4"></textarea><br><br>
<label for="references">Enter Your Business References</label><br>
<textarea rows="4" cols="50" id="references"></textarea><br><br>
<input type="button" onclick="validateEmail()" value="Create Resume">
</form>
</body>
</html>
//js
var elemH1 = document.createElement("h1");
elemH1.style.color = "red";
elemH1.style.fontFamily = "tahoma";
elemH1.style.textAlign = "center";
elemH1.innerText = "Kent Butler";
document.body.appendChild(elemH1);
var elemH2 = document.createElement("h2");
elemH2.style.fontFamily = "garamond";
elemH2.style.color = "red";
elemH2.style.fontStyle = "italic";
elemH2.style.textAlign = "center";
elemH2.innerText = "WEB 115.0001";
document.body.appendChild(elemH2);
var title = document.createElement("h1");
title.style.textAlign = "center";
title.innerText = "Build Your Resume";
document.body.appendChild(title);
function validateEmail(email) {
var name = document.getElementById('name').value;
var address = document.getElementById('address').value;
var phone = document.getElementById('phone').value;
var email = document.getElementById('email').value; //get email id
//var personalInfo = document.getElementById('personalInfo').value;
var objectives = document.getElementById('objectives').value;
objectives.style.textAlign = "right";
//var education = document.getElementById('education').value;
var re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
var testRe = re.test(email);
testRe;
if (testRe != true) {
window.alert("Invalid Email Address. Please Reenter");
}
else {
var myText = ('<html>\n<head>\n<title>Resume</title>\n</head>\n<body>\n');
myText += (name + "<br>" + address + " " + phone + " / " + email + "<br><br>");
myText += ("CAREER OBJECTIVES" + objectives)
myText += ("</body>\n</html>");
var openWindow = window.open('');
openWindow.document.write(myText);
}
}
这不是成品。我还有许多其他字段要创建,但这不会成为问题。我需要能够设置新文档的样式,即正确对齐文本。简历产品的“职业目标”应左对齐,然后html的输入应右对齐。 “ objectives.style.textAlign =”正确“;”不起作用(JS中的第28行)
答案 0 :(得分:0)
我想你想要
var objectives = document.getElementById('objectives');
而不是值