2011-08-12 106 views
0

嗨即時嘗試調用此功能從一個元素,但元素ID是動態的。jQuery/jQuery手機點擊/滑動事件

<script> 
$(function() { 
    $('#showme_').live('swiperight',function(event) { 
    $("#showDel_").show(); 
}); 
</script> 

如果用戶在元素上滑動顯示刪除按鈕。

<div id="swipeme_1">swipe me 
<div id="showDel_1" style="display:none;">DELETE</div> 
</div> 

<div id="swipeme_2">swipe me 
<div id="showDel_2" style="display:none;">DELETE</div> 
</div> 

<div id="swipeme_2">swipe me 
<div id="showDel_3" style="display:none;">DELETE</div> 
</div> 

我可以通過在站點的後端代碼中循環javascript來實現相同的效果。有另一種/更簡單的方法嗎?

問候

+0

例如,如果您使用iPhone上的FB應用,在狀態上向右滑動以顯示刪除按鈕。 – shane

+0

即時通訊使用jquery mobile – shane

回答

2

我不知道哪些插件,您正在使用swiperlight事件。但是,如果你不使用touchwipe插件,那麼我建議你看看這個

http://www.netcu.de/jquery-touchwipe-iphone-ipad-library

示例代碼

$("#showme_").touchwipe({ 
    wipeLeft: function() { alert("left"); }, 
    wipeRight: function() { alert("right"); }, 
    wipeUp: function() { alert("up"); }, 
    wipeDown: function() { alert("down"); } 
    preventDefaultEvents: true 
}); 
+0

感謝您的回覆,#showme_id我如何獲得id。或者是循環中的這個腳本。 – shane

+0

您必須知道要附加滑動事件的元素的ID。將此代碼放置在代碼中的適當位置。 – ShankarSangoli

+0

對不起,如果我不清楚,在第一篇文章中,我作出的div ID是從數據庫中拉,即1,2,3,4等,如果JavaScript是在標題如何將ID從div到JavaScript在標題中。問候 – shane