请写一个html程序目的是通过用户输入的一个关于名字的字符串生成伪随机数根据随机数生成兽人设定要求设定包括性别身高腰围胸围臀围物种体色被毛程度尾巴长短尾巴蓬松程度耳朵轮廓衣着风格毕业大学所学专业出生地居住地等方面。
<!DOCTYPE html>
<html>
<head>
<title>兽人设定生成器</title>
<style>
input[type="text"] {
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
}
button[type="submit"] {
padding: 10px 20px;
font-size: 16px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>兽人设定生成器</h1>
<form>
<label for="name">请输入您的名字:</label>
<input type="text" id="name" name="name" required><br>
<pre><code> <button type="submit" onclick="generate()">生成设定</button>
</form>
<div id="output"></div>
<script>
function generate() {
const name = document.getElementById("name").value;
const sex = Math.random() < 0.5 ? "男" : "女";
const height = Math.floor(Math.random() * 50 + 150) + "cm";
const waist = Math.floor(Math.random() * 10 + 60) + "cm";
const chest = Math.floor(Math.random() * 20 + 80) + "cm";
const hip = Math.floor(Math.random() * 20 + 80) + "cm";
const species = ["狼族", "虎族", "熊族", "狐族", "龙族", "鹰族", "猫族", "猪族"];
const color = ["棕色", "黑色", "灰色", "白色", "黄色", "红色", "绿色", "蓝色"];
const fur = ["全身长毛", "背部长毛", "腹部长毛", "无毛"];
const tailLength = Math.floor(Math.random() * 30 + 10) + "cm";
const tailFluffiness = ["蓬松", "一般", "稀疏"];
const earShape = ["竖耳", "垂耳", "尖耳", "圆耳"];
const style = ["休闲", "运动", "正式", "浪漫", "古风"];
const university = ["清华大学", "北京大学", "复旦大学", "上海交通大学", "浙江大学", "南京大学"];
const major = ["计算机科学与技术", "物理学", "化学", "心理学", "文学", "艺术设计"];
const birthplace = ["北京", "上海", "广州", "深圳", "成都", "杭州"];
const residence = ["北京", "上海", "广州", "深圳", "成都", "杭州"];
const speciesIndex = Math.floor(Math.random() * species.length);
const colorIndex = Math.floor(Math.random() * color.length);
const furIndex = Math.floor(Math.random() * fur.length);
const tailFluffinessIndex = Math.floor(Math.random() * tailFluffiness.length);
const earShapeIndex = Math.floor(Math.random() * earShape.length);
const styleIndex = Math.floor(Math.random() * style.length);
const universityIndex = Math.floor(Math.random() * university.length);
const majorIndex = Math.floor(Math.random() * major.length);
const birthplaceIndex = Math.floor(Math.random() * birthplace.length);
const residenceIndex = Math.floor(Math.random() * residence.length);
const output = document.getElementById("output");
output.innerHTML = `
<p>性别:${sex}</p>
<p>身高:${height}</p>
<p>腰围:${waist}</p>
<p>胸围:${chest}</p>
<p>臀围:${hip}</p>
<p>物种:${species[speciesIndex]}</p>
<p>体色:${color[colorIndex]}</p>
<p>被毛程度:${fur[furIndex]}</p>
<p>尾巴长度:${tailLength}</p>
<p>尾巴蓬松程度:${tailFluffiness[tailFluffinessIndex]}</p>
<p>耳朵轮廓:${earShape[earShapeIndex]}</p>
<p>衣着风格:${style[styleIndex]}</p>
<p>毕业大学:${university[universityIndex]}</p>
<p>所学专业:${major[majorIndex]}</p>
<p>出生地:${birthplace[birthplaceIndex]}</p>
<p>居住地:${residence[residenceIndex]}</p>
`;
}
</script>
</code></pre>
</body>
</html
原文地址: https://www.cveoy.top/t/topic/cbpn 著作权归作者所有。请勿转载和采集!