DOM示例
<iframe id="ueditor_0" width="100%" height="100%" frameborder="0" src="any-path.html">
<!DOCTYPE html>
<html>
<head>
</head>
<body class="view" contenteditable="true" spellcheck="false">
...
</body>
</html>
</iframe>
Javascript代碼
$('iframe#ueditor_0').contents().find("body").bind('keyup', function(event){
alert('any js code');
});
代碼setTimeout看情況使用,例如在百度富文本編輯器ueditor就需要等一下$(document).ready(),這個iframe纔會展開。
具體是:
$(document).ready(function(){
setTimeout('myFnDelayForKeyUp();', 1500);
});
function myFnDelayForKeyUp () {
$('iframe#ueditor_0').contents().find("body").bind('keyup', function(event){
alert('any js code');
});
}