jQuery爲iframe設置onmouseover事件,onkeyup, onkeydown等 - 百度富文本編輯器ueditor修改

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');
    });
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章