簡體   English   中英

$ {location).attr('href'); 不工作

[英]$(location).attr('href'); not working

我不知道為什么,但是這段代碼有問題。 盡管已指定了屬性$ {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而不是其他內容。

返回一個Location對象,該對象包含有關文檔URL的信息並提供用於更改該URL的方法。 您也可以分配給該屬性以加載另一個URL。

位置不是dom中的元素,因此jQuery無法選擇它。

因此,您的代碼將如下所示:

var currentUrl = window.location.href;

location不是DOM 元素 ,它是Location對象 您試圖從中創建一個jQuery對象,但這沒有任何意義。

使用此代替:

var currentUrl = window.location.href;

嘗試這個

 var currentUrl = window.location.href;

嘗試改用var currentUrl = window.location.href 這將返回當前頁面的位置。

代替

$(location).attr('href'); 

采用

currentUrl = location;

好的,我以這種方式進行了更改,但似乎沒有用:

$(document).ready(function() {
var currentUrl = window.location.href;
if(currentUrl == 'http://streamingdb.net/')  
$('#bottombar').show(); 
$("#bottombarClose").click(function() {
$('#bottombar').hide();
});
});

然后我在div#Bottombar中添加了“ display:none”,一切正常。 感謝您的所有時間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM