zoukankan      html  css  js  c++  java
  • js给dropdownlist添加选项

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



    Js代码

    <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>


    后台代码

    返回刚刚插入的目录的id字符串



    上面的代码在360中有错误:可以加载上,但是dropdownList中的列表没有刷新

    改错:

    <script type="text/javascript">
            ////创建新目录
            function newDir() {
                var txt = document.getElementById("newDirtxt");
                var dirname = txt.value;
                if (!dirname) {
                    alert("请填写目录名");
                } else {
                    $.ajax({
                        type: "Post",
                        url: "/center/directorynewPost",
                        async: false,
                        data: { dirname: dirname },
                        success: function(msg) {
                            if (msg.length < 40) {
                                var temp = "<OPTION value=" + msg + ">" + dirname + "</OPTION>";
                                var DirectoryID = $("#DirectoryID");
                                DirectoryID.html(DirectoryID.html() + temp);
                                txt.value = "";
                                alert("增加成功");

                            } else {
                                alert("增加失败");
                            }
                        }
                    });
                } //else
            }
        </script>


  • 相关阅读:
    元素定位不到的问题,Timeout,nosuch element,unable locate等
    webpack的安装
    Mysql修改表
    Mysq表的创建和l数据类型
    Mysql的库操作
    面向对象的序列化和反序列化
    类的关键字:final、const
    面向对象接口以及和继承的混合案例
    DOM创建移除替换元素
    抽象类
  • 原文地址:https://www.cnblogs.com/nanxiaoxiang/p/2942345.html
Copyright © 2011-2022 走看看