首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从链接中打开弹出窗口

无法从链接中打开弹出窗口
EN

Stack Overflow用户
提问于 2020-07-22 09:53:38
回答 1查看 71关注 0票数 1

嗨,伙计们,我有一个小问题,打电话弹出的id从链接。它正在进行单击,但不能从url调用类似exaple.com/#id之类的内容。

代码语言:javascript
复制
(function($) {
$(document).ready(function() {
    //$('a.ajax-post').off('click').on('click', function(e) {
    $("a.ajax-post").on("click", function(e) {
        // show popup 
        $(".popup.supernova").addClass("is-show");

        e.preventDefault(); //Prevent Default Behaviour
        var post_id = $(this).attr("id"); //Get Post ID

        // Ajax Call
        $.ajax({
            cache: false,
            timeout: 8000,
            url: "/wp-admin/admin-ajax.php",
            type: "POST",
            data: {
                action: "theme_post_example",
                id: post_id
            },

            beforeSend: function() {
                $("#ajax-response").html("Loading");
            },

            success: function(data, textStatus, jqXHR) {
                var $ajax_response = $(data);
                $("#ajax-response").html($ajax_response);
                setTimeout(() => {
                    $("#ajax-response").addClass("show-content");
                }, 100);
                /* $(".popup.supernova").append(script); */
            },

            error: function(jqXHR, textStatus, errorThrown) {
                console.log(
                    "The following error occured: " + textStatus,
                    errorThrown
                );
            },

            complete: function(jqXHR, textStatus) {},
        });
    });
});
})(jQuery);
代码语言:javascript
复制
<a href="#" id="8" class="catalog__item popup-8 ajax-post">
    <span class="catalog__title">Title</span>
    <img src="image.jpg" alt="" id="img_8">
</a>

有人能告诉我怎么做吗?以及为什么它不起作用。我是新来的。提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-22 10:47:04

根据您的问题,当exaple.com/#id URL容器#id时,您希望打开

检查URL是否包含#id,然后单击锚标记Programmatically

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63031523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档