Home >Web Front-end >JS Tutorial >A simple example of js determining whether there is a specified control in the page_javascript skills
if (document.getElementById('show_pic')!=null){document.getElementById('show_pic').src=this.value;}
show_pic is a picture control in the page. We must first ensure that this control exists on the page before we can operate it. Otherwise, JS will cause errors, so we use this method to make the judgment. I heard netizens say, There is also a function in JS that can determine whether an object exists, but unfortunately I didn't find it.