我想要这样的JQuery代码
if (current page === something) {
$("div").AddClass("active")
}该怎么做呢?
这是因为我使用的是bootstrap,所以它不允许我使用make :active selector。
我想要这样的效果下的文本:http://imgur.com/eNu8Cp5
请帮帮忙。
发布于 2015-06-27 04:18:53
这只是一个想法:
HTML
<div id="pageid" value="landing">
</div>JS
var page = $('#pageid').attr('value');
alert(page);这是fiddle
发布于 2015-06-27 04:24:56
location.href包含当前页面的URL。所以
if (location.href == something) {
// Do whatever you want
}您还可以使用location.pathname仅获取URL的路径名部分。
if (location.pathname == '/index.html') {
$("div").addClass("active");
}如果你不想显式地匹配目录部分,你可以这样写:
if (location.pathname.indexOf('pluginview.html') != -1) {
$("#pluginviewbody").hide();
}https://stackoverflow.com/questions/31081280
复制相似问题