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

onpaste事件如何拿到粘贴之后的值?
jquery绑定paste事件以后我发现取到的都是粘贴之前的值,如何能取到粘贴之后的值?

------解决方案--------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<title>无标题文档</title>
</head>

<body>
I have a textarea, on paste to that textarea I want to
<textarea id="content" cols="50" rows="5"></textarea>
<script type="text/javascript">
jQuery(function($){
$('#content').bind('paste',function(e){
var pastedText = undefined;
if (window.clipboardData && window.clipboardData.getData) { // IE
     pastedText = window.clipboardData.getData('Text');
   } else {
     pastedText = e.originalEvent.clipboardData.getData('Text');//e.clipboardData.getData('text/plain');
   }
alert(pastedText);
});

});
</script>
</body>
</html>