无法通过IE设置事件 [英] Trouble getting events set with IE

查看:77
本文介绍了无法通过IE设置事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Prototype库进行ajax调用。 (是的,我知道关于原型的

讨论)。 Perhpas它的库是'

导致问题的库,但我现在更加怀疑我自己的代码

我的javascript学习曲线。


这里是带有内联javascript 的测试页面:

http://hank.org/demos/ajax3.html


在Firefox中运行和歌剧。 Safari会看到onclick事件,但是然后

运行默认操作(在链接后面)。 IE根本没有运行事件

处理程序,尽管如警报所示,它正在运行代码

来设置事件。


初始目标是将html与javascript分开 -

,避免在html中使用内联onclick事件。


代码假设找到所有带有类ajaxtarget的元素。 -

是由ajax调用替换的容器。然后通过查找class =" ajax"来找到设置为

的事件。在那个外部

目标内。


在一个oclick事件(在进行ajax调用之前)代码中删除了

事件。从我读过的内容来看,IE需要保持泄漏

内存。在更新DOM之后,重复添加onclick

事件的过程以重置事件。


此时我正在寻求帮助通过IE和Safari获取代码工作,如果




谢谢,

I''m using the Prototype library for ajax calls. (Yes, I''m aware of the
discussions about prototype lately). Perhpas it''s the library that''s
causing problems, but I''m more suspct of my own code at this point in
my javascript learning curve.

Here''s the test page with inlined javascript:

http://hank.org/demos/ajax3.html

Works in Firefox and Opera. Safari sees the onclick events, but then
runs the default action (follows the link). IE doesn''t run the event
handler at all, although as seen with the alerts, it''s running the code
to set the events.

The inital goal was to separate the html from the javascript -- that
is, avoid using inline onclick events in the html.

The code is suppose to find all elements with class "ajaxtarget" --
that is the container that is replace by the ajax call. The events to
set are then found by looking for class="ajax" within that outer
target.

Upon an oclick event (before making the ajax call) the code removes the
events. From what I''ve read that''s needed to keep IE from leaking
memory. After the DOM is updated the process of adding the onclick
events is repeated to reset the events.

At this point I''m looking for help to get the code working, if
possible, with IE and Safari.

Thanks,

推荐答案

你能减少代码并重现问题吗?


彼得

Can you trim the code down and reproduce the problem?

Peter


是的我可以, http://hank.org/demos/ajax4.html


var my_event = function(e){

alert(''点击'');

Updater.click(e,el);

e.preventDefault();

返回false;

};


因此,在IE上调用第一个警报,但不调用Updater.click()调用。

Yes I can, http://hank.org/demos/ajax4.html.

var my_event = function(e) {
alert(''got click '');
Updater.click(e,el);
e.preventDefault();
return false;
};

So, on IE the first alert is called, but not the Updater.click() call.


wh ******* @ gmail.com 写道:
是的我是ca n, http://hank.org/demos/ajax4.html
Yes I can, http://hank.org/demos/ajax4.html.




您还可以摆脱一堆所有样式和一堆html

标签仍然有问题吗?这些东西都不应该导致问题因此删除它会有助于隔离事物。


您提到Safari存在问题。我把代码减少了

甚至更多,只是尝试了OS X 10.3.9上的Safari 1.3.2中的以下内容,并且它工作正常。也适用于Firefox 1.5。很好,我的意思是我看到

两个警报。


如果这在您的浏览器中有效,请尝试重新构建代码,直到它为止b / b
休息。这将为哪条线造成问题提供更好的线索。


彼得

< html>

< head>

< script type =" text / javascript" SRC ="原/的prototype.js" >< / script>

< / head>


< body>

< a id =" ; FOO" style =" cursor:pointer;">点击我!< / a>


< script type =" text / javascript">

var Updater = {

init:function(){

var el =



You could also get rid of a bunch of all styles and a bunch of html
tags and still have the problem? None of this stuff should be causing
the problem so removing it will help isolate things.

You mentioned that there was a problem with Safari. I cut the code down
even more and just tried the following in Safari 1.3.2 on OS X 10.3.9
and it worked fine. Also works in Firefox 1.5. By fine I mean I saw
both alerts.

If this works in your browsers try building the code back up until it
breaks. This will give better clues to which line is causing problems.

Peter
<html>
<head>
<script type="text/javascript" src="proto/prototype.js" ></script>
</head>

<body>
<a id="foo" style="cursor:pointer;">Click me!</a>

<script type="text/javascript">
var Updater = {
init: function () {
var el =


这篇关于无法通过IE设置事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆