我不知道为什么,但我对这段代码有问题。横幅显示在每个页面上,尽管它指定了属性 $(location).attr('href') 你可以帮助我吗?:
<div id="bottombar">
<div class="bottom-content">
<a href="http://www.cliente.org/" target="_blank"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/banner/bottom-logo.png" alt="player-logo" /></a>
<a href="http://www.cliente.org/" target="_blank"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/banner/bottom-txt.png" alt="player-slogan" /></a>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/banner/bottom-download.png" alt="player-download" />
</div>
<div id="bottombarClose"><p>Chiudi</p></div>
<script type="text/javascript"">
$(document).ready(function() {
var currentUrl = $(location).attr('href');
if(currentUrl == 'http://www.esempio.net/')
$('#bottombar').show();
$("#bottombarClose").click(function() {
$('#bottombar').hide();
});
});
</script>
</div>
CSS 代码:
div#bottombar {
background-image: url(images/banner/player-bg3.png);
background-repeat: repeat-x;
bottom: 0;
color: #FFFFFF;
font-family: Arial,Helvetica,sans-serif;
height: 100px;
left: 0;
margin: 0;
position: fixed !important;
width: 100%;
z-index: 99999;
display:none;
}
.bottom-content {
bottom: 0;
height: 97px;
left: 50%;
margin-left: -495px;
position: absolute;
width: 960px;
z-index: 10;
}
#bottombarClose {
cursor: pointer;
float: right;
padding: 55px 10px 0 0;
}
最佳答案
您的意思不是只是location.href
吗?
假设您正在谈论 window.location
而不是其他东西。
Returns a Location object, which contains information about the URL of the document and provides methods for changing that URL. You can also assign to this property to load another URL.
位置不是 dom 中的元素,因此 jQuery 无法选择它。
所以你的代码会像这样:
var currentUrl = window.location.href;
关于javascript - $(位置).attr ('href' );不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5474121/