当然,以下是一个简单的JavaScript个人简介示例代码。这个示例将创建一个包含姓名、职位、技能和联系方式的个人简介卡片,并将其动态添加到网页中。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>个人简介</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.profile-card {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
width: 300px;
}
.profile-card h2 {
margin-top: 0;
color: #333;
}
.skills {
list-style-type: none;
padding: 0;
}
.skills li {
background-color: #e0e0e0;
margin: 5px 0;
padding: 8px;
border-radius: 5px;
}
.contact a {
display: block;
margin: 5px 0;
color: #007BFF;
text-decoration: none;
}
.contact a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div id="profile"></div>
<script>
// 个人简介数据
const profileData = {
name: "张三",
position: "前端开发工程师",
skills: ["HTML", "CSS", "JavaScript", "React", "Node.js"],
contact: {
email: "zhangsan@example.com",
github: "https://github.com/zhangsan",
linkedin: "https://linkedin.com/in/zhangsan"
}
};
// 创建个人简介卡片
const profileContainer = document.getElementById('profile');
const card = document.createElement('div');
card.className = 'profile-card';
const name = document.createElement('h2');
name.textContent = profileData.name;
const position = document.createElement('p');
position.textContent = profileData.position;
const skillsList = document.createElement('ul');
skillsList.className = 'skills';
profileData.skills.forEach(skill => {
const skillItem = document.createElement('li');
skillItem.textContent = skill;
skillsList.appendChild(skillItem);
});
const contactSection = document.createElement('div');
contactSection.className = 'contact';
for (const [key, value] of Object.entries(profileData.contact)) {
const link = document.createElement('a');
link.href = key === 'email' ? `mailto:${value}` : value;
link.textContent = key.charAt(0).toUpperCase() + key.slice(1);
contactSection.appendChild(link);
}
// 组装卡片内容
card.appendChild(name);
card.appendChild(position);
card.appendChild(skillsList);
card.appendChild(contactSection);
// 添加到页面
profileContainer.appendChild(card);
</script>
</body>
</html>
<div>
元素,ID为profile
,用于动态插入个人简介卡片。profileData
对象,包含姓名、职位、技能和联系方式等信息。profile
容器中。这个示例适用于创建静态或动态的个人简介页面,可以进一步扩展以包含更多信息,如教育背景、项目经验、作品集链接等。通过使用JavaScript动态生成内容,可以方便地管理和更新个人简介信息,而无需手动修改HTML结构。
</body>
之前,或者使用DOMContentLoaded
事件监听器。profileData
是否正确定义,并包含预期的数据。通过以上代码和说明,你可以创建一个简洁美观的个人简介页面,并根据需要进行自定义和扩展。
领取专属 10元无门槛券
手把手带您无忧上云