日期:2014-05-16  浏览次数:20324 次

js 捕获ctrl + c / ctrl + v
<html>
<header>
<script>
function keypress()
{
var keyCode = window.event.keyCode;

var opCell = window.event.srcElement;

if(keyCode == "22")
{
// press Ctrl+V keyboard
var txt = clipboardData.getData('text');
if(txt == null) {txt = ""};
opCell.innerText = txt;

}else if(keyCode == "26")
{
// press Ctrl+Z keyboard (ctrl+z只是简单的将这个单元格的值清空,要想恢复上一次值,请用右键)
opCell.innerHTML = " ";
}else
{
if(window.event.srcElement.tagName == "TD"){
mygrid.editCell(window.event);
}
}
}

function keyup()
{
var keyCode = window.event.keyCode;

/* Ctrl+C 事件要在onKeyup事件中捕获 */
if(keyCode == "67")
{
// press Ctrl+C keyboard
var opCell = window.event.srcElement;
clipboardData.setData("text",opCell.innerText);
}
}
</script>
</header>

<body onKeypress="keypress()" onKeyup="keyup();">
</body>
</html>