Mootools 1.2.4 委托在 IE8 中不起作用...?

发布于 2024-08-30 17:13:30 字数 1776 浏览 2 评论 0原文

所以我在表单旁边有一个列表框。当用户单击选择框中的选项时,我会发出对相关数据的请求,这些数据以 JSON 对象返回,然后放入表单元素中。保存表单后,请求将通过,并使用更新的数据重建列表框。由于它正在重建,我尝试在列表框的父 div 上使用委托来执行 onchange 代码。我遇到的问题是 IE8(大震惊)没有触发委托事件。

我有以下 HTML:

<div id="listwrapper" class="span-10 append-1 last">  
<select id="list" name="list" size="20">  
     <option value="86">Adrian Franklin</option>  
     <option value="16">Adrian McCorvey</option>  
     <option value="196">Virginia Thomas</option>  
</select>  
</div>  

和以下脚本:

window.addEvent('domready', function() {     
  var jsonreq = new Request.JSON();  

  $('listwrapper').addEvent('change:relay(select)', function(e) {  
    alert('this doesn't fire in IE8');  
    e.stop();  
    var status= $('statuswrapper').empty().addClass('ajax-loading');  
    jsonreq.options.url = 'de_getformdata.php';  
    jsonreq.options.method = 'post';  
    jsonreq.options.data = {'getlist':'<?php echo $getlist ?>','pkey':$('list').value};  
    jsonreq.onSuccess = function(rObj, rTxt) {  
        status.removeClass('ajax-loading');  
        for (key in rObj) {  
              status.set('html','You are currently editing '+rObj['cname']);  
              if ($chk($(key))) $(key).value = rObj[key];  
        }  
        $('lalsoaccomp-yes').set('checked',(($('naccompkey').value > 0)?'true':'false'));  
        $('lalsoaccomp-no').set('checked',(($('naccompkey').value > 0)?'false':'true'));  
    }  
    jsonreq.send();  
  });  
});  

(我拿出了一些不相关的东西)。因此,这一切在 Firefox 中都按预期工作,但 IE8 拒绝触发 select 元素上的委托更改事件。如果我将更改功能直接附加到选择,那么它就可以正常工作。

我错过了什么吗? IE8 不喜欢 :relay 吗?

旁注:我对 mootools 和 javascript 等非常陌生,所以如果有什么可以在代码方面改进的地方,也请告诉我。 谢谢!

So I have a listbox next to a form. When the user clicks an option in the select box, I make a request for the related data, returned in a JSON object, which gets put into the form elements. When the form is saved, the request goes thru and the listbox is rebuilt with the updated data. Since it's being rebuilt I'm trying to use delegation on the listbox's parent div for the onchange code. The trouble I'm having is with IE8 (big shock) not firing the delegated event.

I have the following HTML:

<div id="listwrapper" class="span-10 append-1 last">  
<select id="list" name="list" size="20">  
     <option value="86">Adrian Franklin</option>  
     <option value="16">Adrian McCorvey</option>  
     <option value="196">Virginia Thomas</option>  
</select>  
</div>  

and the following script to go with it:

window.addEvent('domready', function() {     
  var jsonreq = new Request.JSON();  

  $('listwrapper').addEvent('change:relay(select)', function(e) {  
    alert('this doesn't fire in IE8');  
    e.stop();  
    var status= $('statuswrapper').empty().addClass('ajax-loading');  
    jsonreq.options.url = 'de_getformdata.php';  
    jsonreq.options.method = 'post';  
    jsonreq.options.data = {'getlist':'<?php echo $getlist ?>','pkey':$('list').value};  
    jsonreq.onSuccess = function(rObj, rTxt) {  
        status.removeClass('ajax-loading');  
        for (key in rObj) {  
              status.set('html','You are currently editing '+rObj['cname']);  
              if ($chk($(key))) $(key).value = rObj[key];  
        }  
        $('lalsoaccomp-yes').set('checked',(($('naccompkey').value > 0)?'true':'false'));  
        $('lalsoaccomp-no').set('checked',(($('naccompkey').value > 0)?'false':'true'));  
    }  
    jsonreq.send();  
  });  
});  

(I took out a bit of unrelated stuff). So this all works as expected in firefox, but IE8 refuses to fire the delegated change event on the select element. If I attach the change function directly to the select, then it works just fine.

Am I missing something? Does IE8 just not like the :relay?

Sidenote: I'm very new to mootools and javascripting, etc, so if there's something that can be improved code-wise, please let me know too..
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔戏命师 2024-09-06 17:13:30

元素委派不适用于 IE 中的字段元素(输入/选择/文本区域)。

Element Delegation will not work on field elements (input/select/textarea) in IE's.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文