具體過程不做詳細敘述,直接上代碼:
寫一個彈出框,綁定onclick事件是好像控制不了它的返回值。代碼如下
function createBtn(){
for(var i = 0; i < _this.btn.length; i++){
var btn = document.createElement('span');
btn.id = 'btn_' + i;
btn.innerHTML = _this.btn[i];
btn.style.padding = '5px 15px';
btn.style.background = '#E5E5E5';
btn.style.borderRadius = '5px';
btn.style.marginRight = '15px';
btn.style.cursor = 'pointer';
document.getElementById('btn_box').appendChild(btn);
//btn.onclick = closeBox;
}
}
function closeBox(){
var box = document.getElementById('msg_box');
box.remove();
if(this.id == 'btn_0'){
isBool = true;
}else{
isBool = false;
}
return isBool;
}
以上代碼就是通過onclick事件獲取js函數返回值的全部代碼,希望對大家今後的學習工作有所幫助。