码迷,mamicode.com
首页 > Web开发 > 详细

js 三种事件的绑定

时间:2017-08-11 19:33:34      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:false   src   str   鼠标   resize   添加   dev   down   use   

第一种:前段常规绑定:

    <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 三种事件的绑定

标签:false   src   str   鼠标   resize   添加   dev   down   use   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!