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