在首页上将类别添加到正文 [英] Add Class To Body On Homepage
本文介绍了在首页上将类别添加到正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在首页及其上的body标签中添加一个类.但是,它不起作用.我在干什么?
I'm trying to add a class to the body tag just on the homepage and that it. However, it's not working. What am I doing wring?
<script type="text/javascript">
$(document).ready(function() {
if(window.location.href===window.location.hostname) {
$("body").addClass("home");
}
});
</script>
推荐答案
window.location.href
永远不会与window.location.hostname
相同,因为前者将包含协议部分(例如:http://),而后者则不会. t.
window.location.href
will never be the same as window.location.hostname
since the former will contain protocol part (e.g.: http://) where as the latter doesn't.
这篇关于在首页上将类别添加到正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文