[jQuery] double click - dblclick()

想做的功能為對<table>內的<td>中的文字做出編輯的功能
為了方便,藉由點擊2下來觸發dblclick()來去處理



step 1 . 先對該格<td>給他id="attr_class_"

step 2 . 寫以下的jQuery
$('td[id^="attr_class_"]').bind("dblclick",function(){
  $(this).unbind("dblclick"); // 取消綁訂dblclick,以免再度點擊觸發
  var attr_class = $(this).html();
  var temp = this.id.split('_');
  var item_id;        //商品ID
  item_id = temp[2];

  $(this).html('文字輸入框');
  $('#mod_attr_class').bind("blur",function(){
     $.ajax({
        url: '/majorgls/product/ajax_update_item_attr',
        data: {attr_class:$('#mod_attr_class').val(),item_id:item_id,old_attr_class:attr_class},
        type:"POST",
        dataType:'json',

        success: function(response){
          if(response.status == "true"){
            $(window).unbind('beforeunload');
            window.location.reload();
          }else{
            alert(response.message);
          }
        },

        error:function(xhr, ajaxOptions, thrownError){ 
                console.log(xhr); 
        }
    });
  });
});


留言

這個網誌中的熱門文章

[翻譯] 介紹現代網路負載平衡與代理伺服器

[MySQL] schema 與資料類型優化