jQuery - 以编程方式触发事件 [英] jQuery - Programmatically Trigger Event

查看:139
本文介绍了jQuery - 以编程方式触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式触发jQuery处理的点击事件。这是现在的代码:

I need to programmatically trigger a click event that's being handled by jQuery. Here's the current code:

var $thumbs = $('#PhotoGalleryThumbs .tile');
var $zoom = $('#PhotoGallery #PhotoGalleryZoom img');
var $description = $('#PhotoGallery #PhotoGalleryDescription');

$thumbs.click(function(event) {
    event.preventDefault();
    var $thumb = $(this);
    $thumb.addClass('selected')
        .siblings().removeClass('selected');
    $zoom.attr('src', $thumb.children('a').attr('href'));
    $description.html($thumb.find('img').attr('alt'));
});

我正在研究如何从事件处理代码创建功能,任意调用 $ thumbs 对象中的元素。

I am having a mental block working out how to create a function out of the event handling code and then arbitrarily calling it for an element in the $thumbs object.

推荐答案

$thumbs.click();

这将触发点击事件。这是你要找的吗?

This would trigger the click event. Is this what you're looking for?

这篇关于jQuery - 以编程方式触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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