首页 > Web开发 > 详细

js 三种事件的绑定

时间:2017-08-11 19:22:29      阅读:172      评论:0      收藏:0      [点我收藏+]

第一种:前段常规绑定:

    <button type="button" class="recolor" onclick="reCol(‘rowIndex‘,‘colIndex‘)">重新着色</button>

第2种:js绑定监听事件:

//添加监听器
    table.addEventListener("click", display, false);  
} (generat());

//获取鼠标点击的行和列
function display(event) {
   
    var colIndex = null;
    var rowIndex = null;
    var element = event.srcElement || event.target;
    if (!element) return;
    if (element.tagName != "TD") return;
    colIndex = element.cellIndex;
    rowIndex = element.parentNode.rowIndex;
    console.log("row:" + rowIndex + ", col:" + colIndex);
    return rowIndex, colIndex;
}

第2种:js+“”on“”绑定事件:

document.onmouseup = function (event) {
    console.log(event.target + onmouseup);
    tartgetTd = null;
    coltargetTd = null;
    resizeable = false;
    mousedown = false;
    colmousedown = false;
    colresizeable = false;
    document.body.style.cursor = ‘default‘;
}

 

js 三种事件的绑定

原文:http://www.cnblogs.com/kongbo/p/7347484.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!