网络编程 
首页 > 网络编程 > 浏览文章

怎么通过onclick事件获取js函数返回值(代码少)

(编辑:jimmy 日期: 2025/7/2 浏览:3 次 )

具体过程不做详细叙述,直接上代码:

写一个弹出框,绑定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函数返回值的全部代码,希望对大家今后的学习工作有所帮助。

上一篇:js实现登陆遮罩效果的方法
下一篇:jQuery获取页面及个元素高度、宽度的总结——超实用