[英]Jquery how to trigger click on an element that gains focus
I am working with caph framework and i trying to click in every id focused 我正在使用caph框架,我尝试单击每个已聚焦的id
$(event.currentTarget).on('selected',function() {
var value = $(this).prop('id');
$('#' + $(this).prop('id')).trigger('click');
});
You can access the event target with $(this) in jQuery. 您可以在jQuery中使用$(this)访问事件目标。 To automatically click on the selected element you could do
要自动单击所选元素,您可以执行
$(event.currentTarget).on('select', function() {
$(this).click()
// or $(this).trigger('click')
};
If I understand your question right though you're asking how to click every element with a given ID - please note that you should be using classes for this, as IDs are supposed to be unique. 如果您问如何单击具有给定ID的每个元素,如果我正确理解了您的问题-请注意,您应该为此使用类,因为ID应该是唯一的。 You could achieve that with the following:
您可以通过以下方法实现:
$(event.currentTarget).on('select', function() {
$('.yourClassName').click()
};
This will click on every element with the given class. 这将单击给定类的每个元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.