I have a site I'm working on. I need to be able to perform a specific function if the URL matches a specific URL. Here's an example of what I'm trying to do:
If the URL matches this URL:
http://www.example.com/EIFS-items/search.php?l2=3,15,25
then I want to have jQu开发者_C百科ery add a class of "show" to the div with the class of "content" below.
Is this possible?
<html>
<head>
<title>Title</title>
<style type="text/css">
.content {
display: none;
}
.show {
display: block;
}
</style>
</head>
<body>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div><!-- end .content -->
</body>
</html>
var url = "http://www.example.com/EIFS-items/search.php?l2=3,15,25";
$(function(){
  if (location.href==url){
    $('.content').show();
  }
});
You seem to be looking for the location object, which contains information about the URL of the current page.
Probably will be better to use the querystring location.search than location.href. This would cover subdomains/protocol changes.
if(location.search == "?l2=3,15,25")
    $('.content').addClass('show');
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论