<!DOCTYPE html>
<html>
<head>
<title>HAOHAO</title>
<style type="text/css">
</style>
</head>
<body>
<div id="div">
<input type="button" name="add_input" value="增加" onclick="addInput();">
</div>
</body>
<script type="text/javascript">
var num = 65;
function addInput() {
let br = document.createElement('br');
let div = document.getElementById('div');
div.appendChild(br);
//添加一个input标签,并且换行
let span = document.createElement('span');
let code = numberExchangeCode(num);
span.innerHTML = '选项'+code+':';
div.appendChild(span);
let input = document.createElement('input');
input.setAttribute('class','input_class');
input.setAttribute('type','file');
input.setAttribute('name','name');
//input.setAttribute('value',code);
div.appendChild(input);
div.appendChild(br);
//26个字母循环
if(num >= 90){
num = 65;
}else{
num += 1;
}
}
//数字转字母(大写)
function numberExchangeCode(number) {
return String.fromCharCode(number);
}
</script>
</html>
JS动态创建input
最新推荐文章于 2024-04-28 17:52:26 发布