0

我有这个 :

<div class="wrapper">
     <div class="left1">
     <div id="position" style="background-color:yellow;border:1px solid black;display:none;width:200px;height:200px;"class="PopupDiv";>Position 1<br>Price x<br>Available on xx-xx-xx<br><a href="http://flibay.com/buy.php";>Buy;</a></div>
             <a href="#" onclick="Popup.show('position','reference','center center',{'constrainToScreen':true});;return false;">Details;</a><br>
        <img src="img/banner_1.jpg">
     </div>
     <div class="left2">
    <div id="position" style="background-color:yellow;border:1px solid black;display:none;width:200px;height:200px;"class="PopupDiv";>Position 2<br>Price x<br>Available on xx-xx-xx<br><a href="http://flibay.com/buy.php";>Buy;</a></div>
             <a href="#" onclick="Popup.show('position','reference','center center',{'constrainToScreen':true,'offsetTop':-200});;return false;">Details;</a><br>
        <img src="img/banner_1.jpg">
     </div>
     <div class="left3">
    <div id="poistion" style="background-color:yellow;border:1px solid black;display:none;width:200px;height:200px;"class="PopupDiv";>Position 3<br>Price x<br>Available on xx-xx-xx<br><a href="http://flibay.com/buy.php";>Buy;</a></div>
             <a href="#" onclick="Popup.show('position','reference','center center',{'constrainToScreen':true,'offsetTop':-200});;return false;">Details;</a><br>
        <img src="img/banner_1.jpg">
     </div>
     <div class="left4">
     <div id="position" style="background-color:yellow;border:1px solid black;display:none;width:200px;height:200px;top:50%;left:50%;margin:-(height/2)px 0 0 -(width/2)px;"class="PopupDiv";>Position 4<br>Price x<br>Available on xx-xx-xx<br><a href="http://flibay.com/buy.php";>Buy;</a></div>
             <a href="#" onclick="Popup.show('position','reference','center center',{'constrainToScreen':true,'offsetTop':-200});;return false;">Details;</a><br>
        <img src="img/banner_1.jpg">
     </div>
     <div class="left5">
    <div id="position" style="background-color:yellow;border:1px solid black;display:none;width:200px;height:200px;"class="PopupDiv";>Position 5<br>Price x<br>Available on xx-xx-xx<br><a href="http://flibay.com/buy.php";>Buy;</a></div>
             <a href="#" onclick="Popup.show('position','reference','center center',{'constrainToScreen':true,'offsetTop':-200});;return false;">Details;</a><br>
        <img src="img/banner_1.jpg">
     </div>
     <div class="left6">
    <div id="position" style="background-color:yellow;border:1px solid black;display:none;width:200px;height:200px;"class="PopupDiv";>Position 6<br>Price x<br>Available on xx-xx-xx<br><a href="http://flibay.com/buy.php";>Buy;</a></div>
             <a href="#" onclick="Popup.show('position','reference','center center',{'constrainToScreen':true,'offsetTop':-200});;return false;">Details;</a><br>
        <img src="img/banner_1.jpg">
     </div>
 </div>

它是以 div 为中心的 javascript 弹出窗口,但如果我点击了这 6 个 div 中的任何一个,请在弹出的 onlu 内容中获取 ID 为“position”的第一个 div。如何仅获取我单击的那些 div 的内容?PS Javacript popup.js 来自此链接的我的修改http://www.javascripttoolbox.com/libsource.php/popup/combined/popup.js

4

1 回答 1

1

id对所有 div 都使用相同的。一个在整个文档中id 必须是唯一的。

<div id="position" style="background- ..snip...
          ^^^^^^--- each of these MUST be unique.

尝试重命名它们position1position2等...

重复的 ID 会导致文档无效,并且 getElementById() 不会通过返回所有匹配的元素来弥补您的错误。它会(正确地)假设一个 ID 应该是唯一的,并且只返回第一个匹配的元素。

于 2013-07-26T20:53:52.667 回答