用html写计算机代码
时间: 2023-12-24 07:05:09 浏览: 33
HTML是一种标记语言,主要用于构建Web页面。如果您想在网页上展示计算机代码,可以使用HTML的pre元素和code元素来包裹代码。例如:
```html
<pre>
<code>
// 这里是一个示例计算机代码
function add(a, b) {
return a + b;
}
</code>
</pre>
```
这将在页面上呈现出一个带有代码高亮和缩进的计算机代码片段。您也可以使用其他的代码高亮工具来美化您的代码,比如SyntaxHighlighter或Highlight.js。
相关问题
用HTML写个简历代码
<!DOCTYPE html>
<html>
<head>
<title>我的简历</title>
<style>
body{
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
}
h1{
text-align: center;
font-size: 36px;
margin-top: 50px;
color: #333;
}
h2{
font-size: 24px;
color: #333;
margin-top: 30px;
}
p{
font-size: 18px;
color: #666;
margin-top: 10px;
}
ul{
margin-top: 10px;
list-style: none;
padding: 0;
}
li{
margin-top: 5px;
font-size: 18px;
color: #666;
}
table{
width: 100%;
border-collapse: collapse;
margin-top: 30px;
}
th{
background-color: #333;
color: #fff;
padding: 10px;
text-align: left;
}
td{
background-color: #fff;
padding: 10px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<h1>我的简历</h1>
<h2>个人信息</h2>
<p>姓名:张三</p>
<p>性别:男</p>
<p>出生日期:1990年1月1日</p>
<p>联系电话:13888888888</p>
<p>电子邮件:zhangsan@example.com</p>
<h2>教育经历</h2>
<ul>
<li>2008年-2012年,本科,清华大学,计算机科学与技术专业。</li>
<li>2012年-2014年,硕士,斯坦福大学,计算机科学与技术专业。</li>
</ul>
<h2>工作经历</h2>
<table>
<tr>
<th>时间</th>
<th>公司</th>
<th>职位</th>
</tr>
<tr>
<td>2014年-2016年</td>
<td>谷歌</td>
<td>软件工程师</td>
</tr>
<tr>
<td>2016年-2020年</td>
<td>亚马逊</td>
<td>高级软件工程师</td>
</tr>
</table>
</body>
</html>
用html写一个计算机
抱歉,我是一个语言模型,无法直接展示HTML代码。但是,我可以提供以下HTML代码示例,您可以将其复制并粘贴到HTML编辑器中:
```html
<!DOCTYPE html>
<html>
<head>
<title>计算机</title>
</head>
<body>
<h1>计算机</h1>
<table border="1">
<tr>
<td colspan="4"><input type="text" id="result" disabled></td>
</tr>
<tr>
<td><input type="button" value="7" onclick="insertNumber('7')"></td>
<td><input type="button" value="8" onclick="insertNumber('8')"></td>
<td><input type="button" value="9" onclick="insertNumber('9')"></td>
<td><input type="button" value="+" onclick="insertOperator('+')"></td>
</tr>
<tr>
<td><input type="button" value="4" onclick="insertNumber('4')"></td>
<td><input type="button" value="5" onclick="insertNumber('5')"></td>
<td><input type="button" value="6" onclick="insertNumber('6')"></td>
<td><input type="button" value="-" onclick="insertOperator('-')"></td>
</tr>
<tr>
<td><input type="button" value="1" onclick="insertNumber('1')"></td>
<td><input type="button" value="2" onclick="insertNumber('2')"></td>
<td><input type="button" value="3" onclick="insertNumber('3')"></td>
<td><input type="button" value="*" onclick="insertOperator('*')"></td>
</tr>
<tr>
<td><input type="button" value="0" onclick="insertNumber('0')"></td>
<td><input type="button" value="." onclick="insertDecimalPoint()"></td>
<td><input type="button" value="C" onclick="clearResult()"></td>
<td><input type="button" value="/" onclick="insertOperator('/')"></td>
</tr>
<tr>
<td colspan="4"><input type="button" value="=" onclick="calculateResult()"></td>
</tr>
</table>
<script>
function insertNumber(number) {
var currentResult = document.getElementById("result").value;
document.getElementById("result").value = currentResult + number;
}
function insertDecimalPoint() {
var currentResult = document.getElementById("result").value;
if (currentResult.indexOf(".") == -1) {
document.getElementById("result").value = currentResult + ".";
}
}
function insertOperator(operator) {
var currentResult = document.getElementById("result").value;
if (currentResult != "") {
document.getElementById("result").value = currentResult + operator;
}
}
function clearResult() {
document.getElementById("result").value = "";
}
function calculateResult() {
var currentResult = document.getElementById("result").value;
if (currentResult != "") {
document.getElementById("result").value = eval(currentResult);
}
}
</script>
</body>
</html>
```
这是一个简单的计算器,包含加、减、乘、除和小数点等功能。在HTML中使用了JavaScript来处理用户输入和计算结果。