Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:57:25
Original
1078 people have browsed it

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template