繁体   English   中英

Jquery:div Hyperlink

[英]Jquery: div Hyperlink

在这里知道,我用Jquery和CSS创建了一个无文本,被阻止,可点击的div。 点击后我想在浏览器中加载一个新的URL,从而让我的访问者离开我的网站说stackoverflow.com。 你能用Jquery做到吗? 如果是这样的话?

 #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的代码? 谢谢!

第一部分相对容易:

$("#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白色,alpha透明度为0.10表示完全透明, 1表示完全不透明)。

注意,我不太确定你的'本地网址'是什么意思,但如果你的意思是可以使用相对路径,例如改变:

'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';
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM