2012-06-30 101 views
1

知道這裏, 我用jquery和CSS做了一個無文本,封鎖,div點擊。 點擊後,我想加載一個新的URL到瀏覽器,從而把我的訪客從我的網站說stackoverflow.com。 你可以用JQuery來做到嗎?如果是這樣如何?jquery:div超鏈接

#star{ 
    width:130px; 
    height:40px; 
    outline:1px solid orange; 
    display:block; 
    cursor:pointer; 
    } 

<div id="star">star</div> 

<script>  
    $("#star").click(function(evt){ 
     $(this).html("http://www.stackoverflow.com"); 
    }); 
</script> 

第二個問題 我必須在div透明或空的,所以菜單背景顯示,(無切片)。 我可以或者應該用透明的gif來做這件事嗎?

順便說一句:也如何修改本地URL的代碼? 謝謝!

回答

3

第一部分是比較容易:

$("#star").click(function(evt){ 
    window.location = 'http://stackoverflow.com'; 
}); 

至於透明度,只需添加以下到你的CSS:

#star { 
    /* other stuff */ 
    background-color: transparent; 
} 

或者,如果你不一定需要完整的跨瀏覽器兼容性:

#star { 
    /* other stuff */ 
    background-color: rgba(255,255,255,0.1); 
} 

以上將使元素的background-color白色,機智h的透明度爲0.10完全透明,1完全不透明)。

注意,我不太清楚你的意思「本地URL」,但如果你的意思是它可以使用相對路徑,例如更改:

'http://server.com/news/index.html' 

要:

'http://server.com/some/other/directory/index.html' 

,而不使用在JavaScript的絕對路徑,那麼下面應該工作:

$("#star").click(function(evt){ 
    window.location.pathname = '/somewhere_else/on/the/same/server'; 
}); 
+0

是的!!!!謝謝你:-)! – Starkemp315

+0

非常歡迎你;我很高興得到了幫助! =) –