JQuery click() not fired in ie8

半世苍凉 提交于 2019-12-04 02:04:00

问题


I'm not a javascript professional so I can't solve the following code alone.

I have a delegate function which works fine in IE7. The Problem in IE8 I figuered out is the last jquery-function click(). Does anybody know how I can solve this for IE 8

thank you in advance.

<script type="text/javascript">
function LightboxDelegate(url,caption)
{
$('#impressionen').attr({
href: url,
title: caption,
alt: caption
});
$('#impressionen').lightBox();
$('#impressionen').click();

};

回答1:


I am not sure whether this helps or not. But try replacing

$('#impressionen').click();

with

$('#impressionen').trigger('click');

See

trigger

Trigger an event on every matched element.




回答2:


What is subscribed to that click event?

I would expect the following to work:

//set up event
$('#impressionen').click(function() { 
    alert('it works!');
});

//alert should show in all browsers
$('#impressionen').click();

However this is a simple example - there are other things that can break this. How are you setting up the click event?



来源:https://stackoverflow.com/questions/1906892/jquery-click-not-fired-in-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!