Home  >  Article  >  Web Front-end  >  A simple example of js determining whether there is a specified control in the page_javascript skills

A simple example of js determining whether there is a specified control in the page_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:57:251075browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn