Javascript下拉菜单动态创建节点
今天突然想做个下拉菜单响应动态创建节点文本框的js代码,其实并不是太难
很轻松的便做了出来,但是每次下拉菜单内容变换,去都是在body后面添加子文本框,所以声明了一个count变量,用来计数,以下附上html的测试代码
<html> <head> <title>test js</title> </head> <body> <select name="char" id="test" onchange="abc()"> <option value="">-choose-</option> <option value="aaa">aaa</option> <option value="bbb">bbb</option> <option value="ccc">ccc</option> <option value="ddd">ddd</option> </select> <script> var count=0; function abc () { count++; var xxx = document.getElementById("test").value; if(xxx=="aaa"&&count==1){ var dhy1 = document.createElement("input"); dhy1.type="text"; document.getElementsByTagName("body")[0].appendChild(dhy1); }else if((xxx=="bbb"||xxx=="ccc")&&count==1){ var dhy2 = document.createElement("input"); var dhy3 = document.createElement("input"); dhy2.type="date"; dhy3.type="date"; document.getElementsByTagName("body")[0].appendChild(dhy2) document.getElementsByTagName("body")[0].appendChild(dhy3); }else{ alert("加载完成!"); } } </script> </body> </html>
相关推荐
gufudhn 2020-06-06
nercon 2020-06-02
88274956 2020-11-03
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14