2010-03-02 25 views
0

後,我有如下一個HTML頁面:獲取元素的mouseup

<table cellpadding="1" cellspacing="1" border="1"> 
     <tr> 
      <td id="abc"> 
       <div style="height: 23px; overflow: hidden; position: relative; height: 70px; width: 70px; 
        background-color: red" valign="top" id="dragable3"> 
        <a style="color: white" class="CalendarPlus-Item-2010311422" title="" href="#"><font 
         color="white">New Item</font></a></div> 
      </td> 
      <td> 
       <div id="4" style="width: 80px; height: 80px;"> 
      </td> 
      <td> 
       <div id="5" style="width: 80px; height: 80px;"> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <div id="8" style="width: 80px; height: 80px;"> 
      </td> 
      <td> 
       <div id="7" style="width: 80px; height: 80px;"> 
      </td> 
      <td> 
       <div id="6" style="width: 80px; height: 80px;"> 
      </td> 
     </tr> 
    </table> 

和的jquery.js和文件的javascript:

var DragHandler = { 

// private property. 
_oElem: null, 

// public method. Attach drag handler to an element. 
attach: function(oElem) { 
    oElem.onmousedown = DragHandler._dragBegin; 
    return oElem; 
}, 

// private method. Begin drag process. 
_dragBegin: function(e) { 
    var oElem = DragHandler._oElem = this; 

    if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; } 
    if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; } 

    var x = parseInt(oElem.style.left); 
    var y = parseInt(oElem.style.top); 

    e = e ? e : window.event; 
    oElem.mouseX = e.clientX; 
    oElem.mouseY = e.clientY; 

    document.onmousemove = DragHandler._drag; 
    document.onmouseup = DragHandler._dragEnd; 
    return false; 
}, 

// private method. Drag (move) element. 
_drag: function(e) { 
    var oElem = DragHandler._oElem; 

    var x = parseInt(oElem.style.left); 
    var y = parseInt(oElem.style.top); 

    e = e ? e : window.event; 
    oElem.style.left = x + (e.clientX - oElem.mouseX) + 'px'; 
    oElem.style.top = y + (e.clientY - oElem.mouseY) + 'px'; 

    oElem.mouseX = e.clientX; 
    oElem.mouseY = e.clientY; 

    return false; 
}, 

// private method. Stop drag process. 
_dragEnd: function() { 
    document.onmousemove = null; 
    document.onmouseup = null; 
    DragHandler._oElem = null; 

}, 

_onPostBack: function(form, ehandle, arg) { 
    var theForm = document.forms[form]; 
    if (!theForm) { 
     theForm = document.aspnetForm; 
    } 
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) { 
     theForm.__EVENTTARGET.value = ehandle; 
     theForm.__EVENTARGUMENT.value = arg; 
     theForm.submit(); 
    } 
} 
} 

DragHandler.attach(document.getElementById('dragable3')); 

我如何獲得該元素的DIV下(ID =「dragable3」)被移動。例如:我將div標籤(id =「dragable3」)從td標籤(id = abc)移動到div標籤(id =「6」)。如何在mouseup後獲得div標籤(id =「6」)?

謝謝,

Phong黨。

回答

0

寫下div id = 6的鼠標事件。使用onmouseup或onmouseover。在那裏你可以捕捉鼠標事件並完成需要的東西。

-1

我們無法爲div(id = 6)設置onmouseover或onmouseup,因爲此事件無法觸發。