问题
I have an images with a fading overlay div on hover which displays a text link within.
When the link is clicked it opens a shadowbox with content. I want the whole overlay div to be clickable so I used :
$("div.overlay").each(function(){
$(this).click(function(){
$('a#overlink').trigger('click'); // id of shadowbox link
return false;
});
});
It works fine in FF, Safari & Chrome but IE shows a 'Object doesn't support this property or method' error.
Is there another way of doing this or another method to use?
回答1:
Which version of ie are you using ? I remember that some version of IE don't support clicking objects other than links or buttons :(
perhaps try with a mousedown event as a workaround
回答2:
I wouldn't recommend this approach. Why can't you call the function which handles your anchor's (link's) click event? Or navigate using location from your link. That would make more sense.
回答3:
$("div.overlay").each(function(i,n){
$(n).click(function(e){
//do not need "a" in front of it as #overlink is unique anyways
$('#overlink').trigger('click'); // id of shadowbox link
return false;
});
});
try this and note my comment above your trigger
回答4:
Have you tried:
$('a#overlink').click();
回答5:
Try this:
$("div.overlay").each(function(){
$(this).click(function(){
var $elm = $('a#overlink');
if (document.createEvent) {
var e = document.createEvent('MouseEvents');
e.initEvent( 'click', true, true );
$elm.get(0).dispatchEvent(e);
}
else {
$elm.trigger("click");
}
return false;
});
});
来源:https://stackoverflow.com/questions/6494159/jquery-triggerclick-not-working-in-ie-object-does-not-support-this-prope