开发者

How to add double click event on a table row using javascript?

var nextRow = tbl.tBodies[0].rows.length;
var row = tbl.tBodies[0].insertRow(nextRow);
row.setAttribute('ondblclick', "return move_to_x_graph();");

This code will add a double click event on a row. But the thing is it's not working in case of Internet Explorer.It's working fine in case of all the other browsers.

For adding style I am handling this:

var cell2 = row.insertCell(1);
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer") {
    cell2.style.setAttribute("cssText", "color:black; width:300px;");
} else {
    cell2.setAttribute("style", "color:black; width:300px;");
}

Can anybody help me to add double click event using Javascript that will also w开发者_如何学Pythonork in Internet Explorer?


Don't set event handlers using setAttribute, it doesn't work as you'd expect in IE. Instead set it directly on the equivalent event handler property of the element:

row.ondblclick = function() {
    return move_to_x_graph();
};


With jQuery:

$(row).bind("dblclick", function(){return move_to_x_graph();});

Also, maybe you can add it to the cells instead of the row:

$(row).find("td").bind("dblclick", function(){return move_to_x_graph();});

If you are not using jquery, give it a try, it makes things easier. Or any other framework like Prototype or so.


Instead of passing a string argument. Try passing a function literal like this:

row.setAttribute('ondblclick', function () {return move_to_x_graph();});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜