【发布时间】:2017-02-23 23:16:30
【问题描述】:
如果内部 html 没有分配图像源,我正在尝试将 ID 为 #myComputer 的 img 标签的可见性设置为 false。
HTML
<img id="myComputer" src="assets/myComputer.png">
JS
var myComputer = document.getElementById('myComputer').src;
var myComputerVisible = true;
if(myComputer == ""){
myComputerVisible = false;
};
当我删除源并检查控制台“myComputerVisible”时,即使我删除了 html 中的源,控制台“myComputerVisible”仍然显示为“true”:
<img id="myComputer" src="">
仅纯 Javascript。请指教!谢谢!
【问题讨论】:
标签: javascript html if-statement show-hide