在css中想使用绝对路径来定位图片.但又不能确定web服务器名,要怎样才能在css中得到web服务器名呢?

ls176 2003-08-18 04:49:25
服务器名是 http://www.xxx.com/ 怎样才能在css中取到?
又或者有没有其它的解决方法?
...全文
366 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuruhong 2003-08-19
  • 打赏
  • 举报
回复
css中支持expression表示式,你可以参考一下
ls176 2003-08-19
  • 打赏
  • 举报
回复
在css中可以这样用吗?
liuruhong 2003-08-19
  • 打赏
  • 举报
回复
如果有错,也只是你jscript的问题了,expression是IE支持的,你自己在别的代码中调用getLocation看看啊,faint
ls176 2003-08-19
  • 打赏
  • 举报
回复
别这样说,我就是在css文件中这样使用后发现没有效果,才问的
.setimage
{
background-image: expression(getLocation());
}

<script>

function getLocation(){
if(location.pathname.substr(0,1)=="/")
{
VPATH=location.pathname.split("/")[1];
}
else
{
VPATH=location.pathname.split("/")[0];
}
return "url(/"+VPATH+"/web/frame/public/images/up.gif);";
}
</script>
cloudchen 2003-08-19
  • 打赏
  • 举报
回复
我靠。。。。bc
ls176 2003-08-19
  • 打赏
  • 举报
回复
我说的是css文件.是不是在css文件中也可以用javascript
cloudchen 2003-08-19
  • 打赏
  • 举报
回复
不是说了,可以!就是expression,向下面这个,在css里面table没有cellPadding、cellSpacing属性的,只有js和html标签里面可以设置,通过如下方法可以达到同样的目的

<style>
table { cloudchen:expression(cellSpacing=1,cellPadding=4,border=0);background:#000000;}
td { background:#ffffff;width:40px;height:30px;}
</style>
<TABLE>
<TR><TD></TD><TD></TD></TR>
</TABLE>
ls176 2003-08-19
  • 打赏
  • 举报
回复
我的意思是在css文件中也可以用javascript?
liuruhong 2003-08-19
  • 打赏
  • 举报
回复
可以的,你看看expression就知道了
ls176 2003-08-19
  • 打赏
  • 举报
回复
这段代码能在css中用?
liuruhong 2003-08-19
  • 打赏
  • 举报
回复
<style>
body{
background-image:expression("url("+ getLocation()+"/images/my.gif));
}
</style>
<script>
function getLocation(){
return location.host
}
</script>
你可以参考msdn
ls176 2003-08-19
  • 打赏
  • 举报
回复
怎么用,能否提示一下?
cloudchen 2003-08-18
  • 打赏
  • 举报
回复
<script>
alert(location.protocol+"//"+location.host)
</script>

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧