gpt的回答,亲测可用
[HTML] 纯文本查看 复制代码 <!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>随机汉字生成器</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
#result {
margin-top: 20px;
font-size: 24px;
}
</style>
</head>
<body>
<h1>随机汉字生成器</h1>
<label for="num">选择汉字数量:</label>
<input type="number" id="num" name="num" min="1" max="20">
<button onclick="generateRandomChinese()">提交</button>
<div id="result"></div>
<script>
function getRandomChineseChar() {
const start = 0x4e00;
const end = 0x9fa5;
const randomCode = Math.floor(Math.random() * (end - start + 1)) + start;
return String.fromCharCode(randomCode);
}
function generateRandomChinese() {
const num = document.getElementById('num').value;
let result = '';
for (let i = 0; i < num; i++) {
result += getRandomChineseChar();
}
document.getElementById('result').innerText = result;
}
</script>
</body>
</html> |