我正在尝试根据哈希值是否附加到网址卸载来定位具有唯一 href 值的通用项目类,我想模拟通常在页面上发生的点击。
jQuery:
if(window.location.hash) {
var hash = window.location.hash;
function showHashVideo() {
jQuery("a.btn").attr("href", hash).trigger('click');
}
jQuery(showHashVideo);
}
HTML:
<a class="btn btn-mini" href="#help-video-modal-Graphing" data-url="video-url" data-title="Graphing">Watch Video</a>
最佳答案
据我所知,您想要查找与 A 元素匹配的元素 HREF。你可以这样做:
jQuery("a.btn[href='" + hash + "']").trigger("click");
这将触发对带有 href=hash
的 a.btn
的点击。
关于javascript - jQuery 目标通用类项目,但具有触发单击的唯一 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23612178/