在 jQuery/JS 中使用通配符按类选择元素

问题描述 投票:0回答:0

我看过有关在 CSS 中选择元素的答案,我想知道是否可以在 jQuery 中使用通配符在一行中执行以下操作?

jQuery('.youtube-video-1')[0].contentWindow.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*');
jQuery('.youtube-video-2')[0].contentWindow.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*');
jQuery('.youtube-video-3')[0].contentWindow.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*');

我试过:

jQuery('.youtube-video-\\S*')[0].contentWindow.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*');
jQuery('[class^=youtube-video-]')[0].contentWindow.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*');
jquery jquery-selectors wildcard
© www.soinside.com 2019 - 2024. All rights reserved.