DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> js給dropdownlist添加選項的小例子
js給dropdownlist添加選項的小例子
編輯:關於JavaScript     

復制代碼 代碼如下:
  <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>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved