`

动态添加select选项

 
阅读更多
<!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>无标题文档</title>
<script language="javascript">
function addOption() {
var selectElementNode = document.getElementById("select");

var optionElement = document.createElement("<option>");
var optionText = document.createTextNode("大学");

optionElement.setAttribute("name1", "大学");
optionElement.appendChild(optionText);

selectElementNode.appendChild(optionElement);

}
</script>
</head>

<body>
    <select id="select">
        <option>------选择------</option>
        <option>小学</option>
        <option>初中</option>
        <option>高中</option>
    </select>
    <input type="button" id="add" onclick="addOption();" value="AddOption"/>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics