Home > Web Front-end > JS Tutorial > How does jq determine whether css exists?

How does jq determine whether css exists?

藏色散人
Release: 2020-12-18 10:29:43
Original
3265 people have browsed it

The method for jq to determine whether css exists: first open the corresponding code file; then request the css resource file through ajax; finally, judge based on the http status code, the code is such as "$("#btn" ).click(function(){...}".

How does jq determine whether css exists?

The operating environment of this tutorial: windows7 system, jquery1.12.0 version, this method is applicable to all Brand computer.

Recommended: "jquery video tutorial"

jquery determines whether the css file exists

mainly uses ajax , by requesting the css resource file and judging based on the http status code. If the status code is 200, it exists, if it is 404, it does not exist.

<button id="btn">检测</button>
<script src="http://www.lingchenliang.com/download/jquery-1.12.0.min.js"></script>
<script>
$("#btn").click(function(){
    $.ajax({
        url: &#39;./main.css&#39;,
        type: &#39;GET&#39;,
        complete: function(response){
            if(response.status == 200){
                alert(&#39;有效&#39;);
            }else{
                alert(&#39;无效&#39;);
            }
        }
    });
});
</script>
Copy after login

The above is the detailed content of How does jq determine whether css exists?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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