我有這個奇怪的問題,我試圖創建按鈕,然後分配一個onclick事件給他們。 onclick函數在頁面加載後立即啓動,然後單擊時不執行任何操作。Onclick在開始時激活,然後什麼都不做
var walk = require('walk');
var files = [];
//Scan
var walker = walk.walk('./src/scripts/plugins', { followLinks: false });
walker.on('file', function(root, stat, next) {
listPluginE(stat.name)
next();
});
var walker = walk.walk('./src/scripts/disabledplugins', { followLinks: false });
walker.on('file', function(root, stat, next) {
listPluginD(stat.name,"disabled")
next();
});
function listPluginE(dir) {
//Text
var dir = arguments[0]
var type = "enabled"
var para = document.createElement("p");
var t = document.createTextNode(dir);
para.className = type;
para.appendChild(t);
document.getElementById('enabledSpace').appendChild(para);
//Disable
var disable = document.createElement("button");
var t = document.createTextNode("Disable");
disable.className = "disable";
disable.onclick = test()
disable.appendChild(t);
document.getElementById('enabledSpace').appendChild(disable);
//Delete
var delButton = document.createElement("button");
var t = document.createTextNode("Delete");
delButton.className = "del";
delButton.appendChild(t);
document.getElementById('enabledSpace').appendChild(delButton);
}
function listPluginD(dir) {
//Text
var dir = arguments[0]
var type = "disabled"
var para = document.createElement("p");
var t = document.createTextNode(dir);
para.className = type;
para.appendChild(t);
document.getElementById('disabledSpace').appendChild(para);
//Enable
var enable = document.createElement("button");
var t = document.createTextNode("Enable");
enable.className = "enable";
enable.onclick = test()
enable.appendChild(t);
document.getElementById('disabledSpace').appendChild(enable);
//Delete
var delButton = document.createElement("button");
var t = document.createTextNode("Delete");
delButton.className = "del";
delButton.appendChild(t);
document.getElementById('disabledSpace').appendChild(delButton);
}
function enablePlugin(name) {
name = arguments[0]
fs.rename("./src/scripts/disabledplugins/" + name,"./src/scripts/plugins/" + name)
location.reload();
}
function disablePlugin(name) {
name = arguments[0]
fs.rename("./src/scripts/plugins/" + name,"./src/scripts/disabledplugins/" + name)
location.reload();
}
function test() {
console.log("test")
}
這似乎解決了問題!但有一個問題。在成品中,我將使用disablePlugin(name)和enablePlugin(name)如何使用參數? – Ezcha
@Minecheese,你打算將哪些變量轉換爲這些函數? –
我打算通過dir – Ezcha