<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title></title>
</head> <body>
<div id="div1"></div>
<div class="div2"></div>
</body> dom基础 </html>
<script>
//<!--文档对象模型
//第一步:取对象 -->
var div1 = document.getElementById('div1') // id取对象
var div2 = document.getElementsByClassName('div2')[] // class名取对象
//第二步操作对象
//1 改内容
div1.innerHTML = "<b>加粗</b>"
div2.innerText = "<b>加粗</b>"
//2 改样式
div1.style.color = "blue";
div1.style.fontFamily = "华文彩云";
//3 加事件
div1.onclick=(){
alert("点击事件出发")
}
//造新元素
var new_div=document.createElement("div")
//改样式/改内容
new_div.innerHTML="新元素"
document.body.appendChild(new_div);//增加
document.body.removeChild(new_div);//删除
</script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
#s1{
width: 100px; //下拉按钮宽度100像素
}
</style>
</head>
<body>
<form action="" method="get"> //表单,提交方式为get <input type="text" name="t1" id="t1" /> //文本框,名字为t1,地址为t1
<input type="button" id="but1" value="添加"/> //名称为添加,地址为but1的按钮
<select size="" id="s1" > // 地址为s1,下拉项为7的下拉菜单
<input type="button" id="but2" value="删除"> //名称为删除,地址为but2的按钮 </select>
</form>
</body>
</html>
<script>
var s1=document.getElementById("s1") //创造新元素s1为从地址s1取得数
var t1=document.getElementById("t1")
var but1=document.getElementById("but1")
var but2=document.getElementById("but2")
but1.onclick=function(){ //当点击添加按钮时,
// 下拉菜单添加从文本框中提取的值
s1.innerHTML+="<option>"+t1.value+"</option>"
t1.value="";
}
but2.onclick=function(){
s1.removeChild(s1.selectedOptions[]); //当点击删除按钮时,选中的选项的元素被移除
} </script>

最新文章

  1. 一个简单oop的changeTab
  2. 免杀后门之MSF&amp;Veil-Evasion的完美结合
  3. 在后台启动受管服务器经常报错:Server may already be running
  4. jQuery的编码标准和最佳实践
  5. Mac 自带 apache
  6. https双向认证demo
  7. 【js】正则表达式豁然开朗
  8. Line Search and Quasi-Newton Methods
  9. 每天一道LeetCode--342. Power of Four
  10. 排序并获取index的顺序
  11. sql 行转列 PIVOT 列转行 UNPIVOT
  12. NYOJ--32--SEARCH--组合数
  13. Windows系统CMD下常用命令
  14. SuperMap -WebGL 实现地球的背景透明并显示自定义图片
  15. (转) Hadoop1.2.1安装
  16. 【11-13】A股主要指数的市盈率(PE)估值高度
  17. vsftpd下错误之:500 OOPS
  18. BZOJ 1005: [HNOI2008]明明的烦恼(prufer数列)
  19. Hibernate关联关系映射之一对一关联关系
  20. logging模块讲解

热门文章

  1. PAT-B 1003. 我要通过!(20) Java版
  2. 微服务实战——高可用的SpringCloudConfig
  3. TensorFlow系列专题(七):一文综述RNN循环神经网络
  4. nodejs 模块加载顺序
  5. 使用FME平移shapefile文件
  6. (note)从小白到产品经理之路
  7. 使用charAt()方法查找字符串
  8. python中的可变和不可变对象 有序和无序对象
  9. 移动自动化appium(2)- Allure报告使用详解
  10. 使用 Visual Studio 开发、测试和部署 Azure Functions(一)开发