2010-04-20 16 views
1

我正在構建一個界面,用於在日曆上標記日期作爲預訂。用戶在他們想標記爲已預訂的日期「繪畫」。jquery:在mouseup()上解除綁定mousenter()的問題()

這裏是它的外觀:

alt text http://i39.tinypic.com/4zyu7t.jpg

這裏的功能是:

function load_red_paint(){ 
    $('td').bind('mousedown', function(){ 
     $(this).addClass('booked'); 
     $('td').bind('mouseenter', function(){ 
      $(this).addClass('booked'); 
     }); 
    unbind_brush(); 
    }) 
} 

function unbind_brush(){ 
    $('td').bind('mouseup', function(){ 
     $('td').unbind('mouseenter'); 
    }); 
    $('table').bind('mouseleave', function(){ 
     $('td').unbind('mouseenter'); 
    }); 
} 

問題:除了如果

我unbind_brush()函數的偉大工程用戶mouseup在日曆之外,在這種情況下,在返回日曆時刷子是s直到'繪畫'。我試圖解決這個問題也是我解除綁定與該位是日曆的鼠標離開:

$('table').bind('mouseleave', function(){ 
    $('td').unbind('mouseenter'); 
}); 

,但沒有快樂,我失去了一些東西很明顯!

編輯:加入HTML:

<div class="table_wrap"> 
     <p class="table_title">Apr</p> 
     <table cellpadding='10'> 

      <tr class="col_titles"> 
       <td>S</td> 
       <td>S</td> 
       <td>M</td> 
       <td>T</td> 
       <td>W</td> 

       <td>T</td> 
       <td>F</td> 
      </tr> 

      <tr> 
      <td class='indent'> </td><td class='indent'> </td><td class='indent'> </td><td class='indent'> </td><td class='indent'> </td><td id='1270080000' class='past '> 01 </td><td id='1270166400' class='past '> 02 </td></tr><tr><td id='1270252800' class='past '> 03 </td><td id='1270339200' class='past '> 04 </td><td id='1270425600' class='past '> 05 </td><td id='1270512000' class='past '> 06 </td><td id='1270598400' class='past '> 07 </td><td id='1270684800' class='past '> 08 </td><td id='1270771200' class='past '> 09 </td></tr><tr><td id='1270857600' class='past '> 10 </td><td id='1270944000' class='past '> 11 </td><td id='1271030400' class='past '> 12 </td><td id='1271116800' class='past '> 13 </td><td id='1271203200' class='past '> 14 </td><td id='1271289600' class='past '> 15 </td><td id='1271376000' class='past '> 16 </td></tr><tr><td id='1271462400' class='past '> 17 </td><td id='1271548800' class='past '> 18 </td><td id='1271635200' class='past '> 19 </td><td id='1271721600' class='hand today '> 20 </td><td id='1271808000' class='hand '> 21 </td><td id='1271894400' class='hand '> 22 </td><td id='1271980800' class='hand '> 23 </td></tr><tr><td id='1272067200' class='hand '> 24 </td><td id='1272153600' class='hand '> 25 </td><td id='1272240000' class='hand '> 26 </td><td id='1272326400' class='hand '> 27 </td><td id='1272412800' class='hand '> 28 </td><td id='1272499200' class='hand '> 29 </td><td id='1272585600' class='hand '> 30 </td></tr><tr>   </tr> 

     </table> 
+0

後的HTML代碼。 jQuery代碼沒有任何問題。這可能是其他方面的副作用。 – kgiannakakis 2010-04-20 09:32:18

回答

0

我測試你的代碼,它工作正常。檢查你是否不小心使用緩存的舊版本的代碼。

+0

沒有運氣與緩存清除, 剛剛嘗試chaning到:$('body')。bind('mouseup'....但沒有更好 – Haroldo 2010-04-20 10:45:26

0

解決了這個問題,感謝kgiannakakis,讓我看看其餘的代碼。

我解除綁定別的地方也因此事件發生衝突..