Home > Backend Development > PHP Tutorial > How to avoid the non-existence of a certain element in html causing js to obtain the attribute information of the element and report an error

How to avoid the non-existence of a certain element in html causing js to obtain the attribute information of the element and report an error

WBOY
Release: 2016-09-09 08:13:15
Original
907 people have browsed it

The page code is as follows:

<code><empty name="search_data">
    <div class="box">
        <!-- html代码 -->
    </div>
</empty>

<script>
    var top = $('.box').offset().top;
    $("html,body").scrollTop(top);
</script></code>
Copy after login

As above, is a thinkphp syntax tag, which means that when "search_data" does not exist, the div element with class box will be output to the page. On the contrary, if the "search_data" data exists, the page will not have the div box. , in this case, how to avoid js error?

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