在html中存在多个option和value,怎样在js脚本中创建对应复选框,框后面显示option的value值
2个回答
2013-10-25
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>test</title>
</head>
<body>
<select id="select1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<div id="div1"></div>
<script type="text/javascript">
<!--
window.onload=function(){
var oSel = document.getElementById("select1");
var oDiv = document.getElementById("div1");
for(var i=0;i<oSel.length;i++){
var oCk = document.createElement('input');
var oSpan = document.createElement('span');
oCk.type = "checkbox";
var optv = oSel.options[i].value;
oCk.value = optv;
var txt = document.createTextNode(optv);
oSpan.appendChild(txt);
oDiv.appendChild(oCk);
oDiv.appendChild(oSpan);
}
};
//-->
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询