复制代码 代码如下:
  <input name="" type="text"  id="newDirtxt"/>

<input class="btn" name="" type="button" value="创建新目录"  onclick="newDir()" />
 

?<BR><BR><BR>Js代码 <BR><BR><script type="text/javascript">
////创建新目录
        function newDir() {
            var txt = document.getElementById("newDirtxt");
            var dirname = txt.value;
            if (dirname) {
                alert("请填写目录名");
            } else {
                $.ajax({
                    type: "Post",
                    url: "/center/directorynew",
                    async: false,
                    data: { dirname: dirname },
                    success: function(msg) {
                        if (msg.length < 40) {
                            var DirectoryID = document.getElementById("DirectoryID");
                            var tOption = document.createElement("Option");
                            tOption.text = dirname;
                            tOption.value = msg;
                            DirectoryID.appendChild(tOption);
                            txt.value = "";
                            alert("增加成功");

                        } else {
                            alert("增加失败");
                        }
                    }
                });
            }//else
        }
    </script><BR><BR><BR>后台代码 <BR><BR>返回刚刚插入的目录的id字符串 <BR>

标签:
js,dropdownlist

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“js给dropdownlist添加选项的小例子”

暂无“js给dropdownlist添加选项的小例子”评论...