【问题标题】:Detect url hash value to trigger click event检测url hash值触发点击事件
【发布时间】:2014-06-27 15:12:45
【问题描述】:

尝试检查当前 url 是否具有 #video-value 哈希值,如果它确实运行用于同一页面上的标记链接操作的相同点击操作。

jQuery 代码:

<script type="text/javascript">
jQuery(document).ready(function () {
function showVideo() {
    var $anchor = jQuery(this),
        url = $anchor.data("url"),
        title = $anchor.data("title");
    jQuery("#help-video-iframe").css("visibility", "hidden");
    jQuery("#help-video-iframe").addClass("loading");
    jQuery("#help-video-iframe").load(function() {
        jQuery("#help-video-iframe").css("visibility", "visible");
    });
    jQuery("#help-video-div-label").empty().append(title);
    jQuery("#help-video-iframe").attr("src", url);
}

jQuery(function() {
    jQuery("#help-videos-list a").click(showVideo);
    jQuery("#help-videos-list .caption").equalizeHeights();
});

});

</script>

【问题讨论】:

    标签: jquery hash click


    【解决方案1】:

    检查是否存在任何哈希值:

    if ( window.location.hash ) {
        //do something
    }
    

    要手动设置哈希,你可以这样做:

    window.location.hash = 'some-hash';
    

    【讨论】:

    • 对不起,我不是很清楚,我只是想知道它是否有任何哈希值而不是那个明确的哈希值。如何使哈希值与单击页面上的 相同。还允许在我拥有的几个 的页面上进行标准的在线点击。
    • 我不确定你在问什么。有关一般概念,请参阅我的更新答案。
    • 我想使用与showVideo()相同的功能。对于页面点击以及 url 末尾是否有哈希。但是现在我需要将哈希值传递给 showVideo() 函数以针对该项目而不是从点击操作中获取的 jquery(this)。
    猜你喜欢
    • 2014-06-06
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 2011-11-19
    • 1970-01-01
    相关资源
    最近更新 更多