以下代码是为了切换提交按钮的可见性而编写的。你能解释一下条件 IF 语句吗?
function ToggleVisibility(){
var b ='btn_Submit,btn_Abort_Master';
var temp = new Array();
temp = b.split(',');
var el;var i=0;
for(i=0;i<temp.length;i++){
try{
el = document.getElementById(temp[i]);
}catch(e){
try{
el = document.all[temp[i]];
}catch(e){}
}
if (el && (el = el.style) && ('string' == typeof el.visibility){
el.visibility = ('hidden' == el.visibility ? 'visible' :'hidden');
}
}
return true;
}
最佳答案
它检查以下条件:
- 变量 el 有值(意味着 document.getElementById(temp[i]) 或 document.all[temp[i]] 方法调用返回一个元素)
- 元素 el 具有已定义的样式属性
- style.visibility 属性值的类型是字符串
关于javascript - 无法理解条件 IF 语句代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32375328/