我在使用IE7(和IE8)時遇到困難。 它是一個非常複雜的腳本非常簡化的一部分。所以請記住,方法和結構不能改變太多。Mootools事件在IE7/IE8中導致無限循環
在IE7中,當選擇其中一種類型時,我得到一個無限循環。在FF,Chrome和IE9中,它工作正常。它與IE7/IE8中的mootools 1.1庫很好地合作,但是因爲我將它轉換爲Mootools 1.4,所以我得到了這個循環問題。
也許某種事件委託在框架中發生變化。我真的不知道。 任何幫助,非常感謝!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>eventz</title>
<script src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools-yui-compressed.js" type="text/javascript"></script>
<script type="text/javascript">
var eventz = new Class({
options: {
},
initialize: function(options) {
this.setOptions(options);
this.setup();
this.jx = 0;
},
setup: function() {
this.makeEvents();
// ...
},
makeEvents : function() {
alert("init");
var finputs = $$('.trig');
finputs.removeEvents('change');
finputs.removeEvents('click');
finputs.each(function(r) {
$(r).addEvents({
'change': function(e) {
//e.preventDefault();
alert(r.name);
new Event(e).stop();
this.refresh(r); // this needs to stay as refresh calls some ajax stuff
}.bind(this)
});
}.bind(this));
// ...
},
// refresh is called from various methods
refresh : function(el) {
if(el) {
// count types checkboxes
var ob_checked = 0;
$$('.otypes').each(function(r) {
// uncheck all if clicked on "All"
if(el.id == 'typ-0') {
r.checked = false;
}
r.checked == true ? ob_checked++ : 0 ;
})
// check "All" if non selected
if(ob_checked == 0) {
$('typ-0').checked = true;
}
// uncheck "All" if some selected
if(el.id != 'typ-0' && ob_checked != 0) {
$('typ-0').checked = false;
}
// ajax call ...
}
}
});
eventz.implement(new Options);
window.addEvent('domready', function(){
c = new eventz();
});
</script>
</head>
<body>
<fieldset class="types">
<input type="checkbox" class="trig" name="otypes[]" value="0" id="typ-0" checked="checked">All
<input id="typ-14" value="14" name="otypes[]" type="checkbox" class="otypes trig">Type A
<input id="typ-17" value="17" name="otypes[]" type="checkbox" class="otypes trig">Type B
</fieldset>
</body>
</html>
謝謝您的回答!我會在稍後開始處理它。使用set並獲取訪問器不會觸發事件泡泡? – Mike 2012-04-17 09:12:03
刷新一下,看看http://jsfiddle.net/M2dFy/2/ – 2012-04-17 09:18:08
不工作在IE8? – Mike 2012-04-17 09:23:02