我想做自定義確認功能。如何使功能如確認
所以,我做出這樣的代碼:
function confirm(msg){
var obj = document.createElement("div");
var body = document.createElement("div");
body.innerHTML = msg;
var foot = document.createElement("div");
var ok = document.createElement("div");
ok.innerHTML = "OK";
var cancel = document.createElement("div");
cancel.innerHTML = "Cancel";
foot.appendChild(ok);
foot.appendChild(cancel);
obj.appendChild(body);
obj.appendChild(foot);
document.getElementsByTagName("body")[0].appendChild(obj);
ok.onclick = function(){
return true;
}
cancel.onclick = function(){
return false;
}
}
或
returnValue = -1;
ok.onclick = function(){
returnValue = true;
}
canacel.onclick = function(){
returnValue = false;
}
while(true){
if(returnValue !== -1) break;
}
return returnValue;
如果這個自定義功能確認必須得到1個參數像原來確認的功能。
如何讓自定義功能確認?
你不能這樣做在JavaScript中睡覺,因此不可能取代了確認,並直到用戶選擇的東西有它暫停執行。你需要使用回調。 – epascarello 2013-03-03 06:17:37