如何在嵌入对象中获得“cursor:pointer”?

8

1) 我正在尝试将一个透明的图片放在嵌入对象上方。但是我似乎缺少了位置,相对和绝对定位的某些设置。但是具体是哪里呢?

我实际上要放置透明图片是因为无法对对象嵌入使用cursor:pointer。所以我的想法是放置一个透明图片并使用cursor:pointer

2) 为什么onclick在IE中无效?它在Firefox和Chrome中都能正常工作。

<div id="divmarquee" runat="server" >
     <img id="imgtrans" runat="server" src= "/images/480x75-blank-transparent" title="Click Here" style="position:relative" />
           <object width="475px" height="75px" onclick="window.location='http://www.google.com'; return false;">
                 <embed src="merchant_images/The_Marquee_Dealn.swf" type="application/x-shockwave-flash" style="z-index: 0; cursor:pointer" wmode="transparent" width="475px" height="75px"> 
                 </embed>
            </object> 
  </div>

提前感谢您!


一个更加切中要害的问题是“如何在嵌入对象上获得cursor:pointer”。 - Jack Marchetti
7个回答

1
使用您提供的代码,在#divmarquee上添加位置值到position: relative,并将位置更改为position: absolute,在#imgtrans上添加cursor: pointer
#divmarquee { position: relative; }
#imgtrans { position: absolute; cursor: pointer; }

请看这里:http://jsfiddle.net/blineberry/pJZ2t/

0

针对您的onclick问题,请尝试以下解决方案:

首先,尝试

onclick = function(){window.location='http://www.google.com';return false;}

然后尝试将其更改为这个:

onclick = window.location.href='somesite'

你也可以尝试:

onclick = document.location='somesite'

如果那不起作用,请尝试:

var el = document.getElementById("imgtrans").firstChild;
if (el.addEventListener){
  el.addEventListener(
      'click', 
      function(){
               window.location='http://www.google.com';
               return false;},
      false); //Decent Browsers
       } 
else if (el.attachEvent){
      el.attachEvent(
          'onclick',
          function(){
               window.location='http://www.google.com';
               return false;
          }
      ); 
}//IE

其中一个会起作用


0
<div id="divmarquee" runat="server" style="z-index: 1; position:relative; cursor:pointer">   
 <div style="z-index: 0; position:relative">
<object width="475px" height="75px" onclick="window.location='http://www.google.com'; return false;">
<embed src="merchant_images/The_Marquee_Dealn.swf" type="application/x-shockwave-flash" wmode="transparent" width="475px" height="75px">
</embed>
</object>
</div>
</div>

0
将“cursor: pointer”样式应用于div marquee。

0
在你上面的代码中,你给嵌入标签添加了cursor: pointer。尝试将其移动到图像标签中。

0
不要使用 <img>,而是使用 <div> 并确保它扩展到对象的宽度和高度。

-1

cursor: pointer 只有在将对象包装在 HTML 超链接中时才有效。


我确实尝试过,但它不起作用。:( 你知道其他的方法吗? - Remo
你尝试过移除 z-index 并使用 <a> 标签吗?因为 IE 经常在 z-index 上出现问题。 - Mr A
只要你为锚点设置了href,这将起作用。最好在onclick处理程序中使用preventDefault / return false来确保链接不会尝试导航。 - steve_c

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接