我看了很多关于 SO 的例子,但似乎看不出我的代码有什么问题:
我有一些 url 带有散列标签/跳转到附加到它们的 id 值。我想检查 url 是否有哈希标记,并将该值用作单击事件,就像我在单击按钮时在页面上所做的那样。
示例网址: http://domain.com/#help-video-modal-tags
j查询代码:
jQuery(document).ready(function() {
if ( window.location.hash ) {
function showVideo() {
alert('in the function');
}
jQuery(window.location.hash).click(showVideo);
}
});
当前点击事件触发函数
showVideo();
最佳答案
使用这个
jQuery(document).ready(function() {
if ( window.location.hash ) {
function showVideo(hash) {
alert('in the function, hash -> ' + hash);
}
jQuery(document).click(showVideo(window.location.hash));
}
});
关于javascript - jquery检测url触发点击事件中的hash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23220679/