【发布时间】:2011-04-21 06:17:11
【问题描述】:
应该触发一些东西,不是吗? 我在 IE8 中不受支持,在 Fx 3.6.10 中没有发生任何事情
<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.2.js"></script>
<script>
// modified from http://pragmatec.blogspot.com/2009/06/google-toolbar-style-and-tooltip.html
jQuery(function($){
$.fn.dommodhandler = function(options){
function setListeners(){
if (typeof (this.onpropertychange) == "object"){
$('#innerDiv').bind('propertychange',function(e){
$('#msgDiv').html(this.id+' changed</br/>');
});
}
else if ($.browser.mozilla){
$('#msgDiv').html("bind");
$('#innerDiv').bind('DOMAttrModified',function(e){
$('#msgDiv').html(this.id+' changed</br/>');
});
}
else {
$('#msgDiv').html('not supported in this browser');
return false;
}
}
return setListeners();
}
}
);
$(document).ready(function(){
$.fn.dommodhandler ();
});
</script>
</head>
<body>
<div id="wrapper">
<a href="#" onClick="document.getElementById('innerDiv').height='300px';document.getElementById('innerDiv').innerHTML=new Date(); return false">Click</a>
<div id="outerDiv">
<div id="innerDiv">Hello</div>
</div>
<div id="msgDiv"></div>
</div>
</body>
</html>
更新:仍然不高兴...任何人有任何建议来检测什么时候(ajax)由于内容更大或更小而改变了 div 的实际高度
【问题讨论】:
-
我会将
if (typeof (this.onpropertychange) == "object")更改为if ("onpropertychange" in this)。在元素具有现有onpropertychange处理程序的情况下,typeof可以返回"function"。
标签: jquery dom javascript-events event-handling