jQuery可以检测特定的URL并根据该URL执行功能吗? [英] Can jQuery detect a specific URL and perform a function based off that URL?
本文介绍了jQuery可以检测特定的URL并根据该URL执行功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个正在工作的网站.如果URL匹配特定的URL,我需要能够执行特定的功能.这是我要执行的操作的示例:
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:
如果URL与该URL匹配:
If the URL matches this URL:
http://www.example.com/EIFS-items/search.php?l2 = 3,15,25
然后我想让jQuery在div中添加一个"show"类,并在下面添加"content"类.
then I want to have jQuery add a class of "show" to the div with the class of "content" below.
这可能吗?
<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();
}
});
这篇关于jQuery可以检测特定的URL并根据该URL执行功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文