DedeCMS 的 TAG 欄位預設只能手動輸入,漏字、錯字都很常見。以下透過五個小改動,讓編輯可以直接從現有的 TAG 列表中點選,不再需要憑記憶打字。
開啟 \dede\templets\album_add.htm,在顶部 head 的 script 區加入:
function setag(){
var tagg = window.showModalDialog("tags_main.php", "tag",
"dialogWidth=800px;dialogHeight=600px");
if(typeof(tagg) != 'undefined') document.form1.tags.value = tagg;
}
在 Tag 標籤輸入的那個 td 裡補上一顆按鈕:
<input type="button" onclick="setag()" value="選擇"
style="width:70px;cursor:pointer;" />
開啟 \dede\templets\tags_main.php,在 head 的 script 區加入:
// 選擇關鍵字
var tag = "";
function selectTag(str) {
tag = tag + "," + str;
if (tag.substr(0, 1) == ',') tag = tag.substr(1);
$("#selecttag").val(tag);
}
function selectTagOK() {
window.returnValue = $("#selecttag").val();
window.close();
}
在 body 中你希望顯示的位置插入:
<div style="padding-left:20px;border:1px"> 所選 TAG: <input type="text" id="selecttag" name="selecttag" size="80" /> <input type="button" onClick="selectTagOK()" value="確定選擇" /> </div>
找到 TAG 列表中的這段:
<a href="../tags.php/?<?php echo urlencode($fields['tag']); ?>/"
target="_blank">{dede:field.tag /}</a>
改成:
<a href="../tags.php/?<?php echo urlencode($fields['tag']); ?>/"
target="_blank">{dede:field.tag /}</a>
<a href="#" onclick="selectTag('{dede:field.tag /}')">[選擇]</a>
使用畫面如下:

其他新增頁(如其他頻道的 add 頁)也可參照同樣的方式補上 script 與按鈕。
1. showModalDialog 已被淘汰。它在大陸以外的環境與新版 Chrome、Firefox 中已移除,不建議再用於新專案;替代方案是 window.open 搭配 window.opener 回傳值,或直接用一個頁內彈出層(modal)呈現 TAG 列表。
2. 修改核心模板會被升級覆蓋。建議把改動集中記錄下來,或使用 DedeCMS 的後台外掛機制。
3. 字串拼接要處理引號。TAG 名稱若含單引號會破壞 onclick,記得先轉義。
4. 後端仍應過濾。tags 欄位的最終內容要在伺服器端做長度與字元過濾,避免注入。