列表注册自定义鼠标右键事件

循环是因为列表中每一个都需要注册

$("#num").val() 总数

$("#fileList-" + i).attr("data-id");主键

window.onload = function () {
  for (var i = 0; i < $("#num").val() ; i++) {
    document.getElementById("fileList-" + i).oncontextmenu = function (e) {
    e.preventDefault();
    };
    debugger;
    var id = $("#fileList-" + i).attr("data-id");
    //自己定义事件的函数
    document.getElementById("fileList-" + i).onmouseup = function (oEvent) {
      if (!oEvent) oEvent = window.event;
        if (oEvent.button == 2) {
          alert(id)
        }
    }
  }
}

猜你喜欢

转载自www.cnblogs.com/otsf/p/11249352.html