【问题标题】:Jquery Tooltipster - access DOM after ajaxJquery Tooltipster - ajax 后访问 DOM
【发布时间】:2021-01-28 02:17:44
【问题描述】:

我在使用 jquery 插件 Tooltipster 和 ajax 时遇到了一些问题:

  1. 我点击一个链接来启动 tooltipster -> 好的
  2. 我得到一个带有 ajax 的表单 -> 好的
  3. 我想与表单的输入进行交互 -> 不行

这是我的代码:

    var id = $(this).attr("scope");
    var tp = $(this).attr("id");
    $(this).tooltipster({
                interactive:true,
                contentAsHTML: true,
                position: 'top',
                content: 'Chargement...',
                delay: '0',
                speed: 150,
                trigger: 'click'
                functionBefore: function(origin, continueTooltip) {
                    continueTooltip();      
                    $.ajax({
                        type: 'GET',
                        url: '/ajax/platform.php',
                        data: {variable1: variable1, variable2: variable2},
                        success: function(data) {
                            origin.tooltipster('content', data).data('ajax', 'cached');
                        }
                    });
                },
                theme: 'tooltipster-shadow'
            });
    });

Ajax 向我发送 html 之类的:

<input type="text" name="input1" id="input1">

如何使用 jquery 与 #input1 进行交互?

【问题讨论】:

  • 你试过什么?您是否尝试过阅读 jquery 选择器文档?
  • 我有类似的东西: $(document).ready(function() { $( document ).on( "click", "#input1", function(e) { alert("It作品"); }); });
  • HTML 加载了 ajax 和 tooltipser,所以我应该把这段代码换成另一种我猜的方式......

标签: jquery ajax tooltipster


【解决方案1】:

它是这样工作的:

var id = $(this).attr("scope");
var tp = $(this).attr("id");
$(this).tooltipster({
            interactive:true,
            contentAsHTML: true,
            position: 'top',
            content: 'Chargement...',
            delay: '0',
            speed: 150,
            trigger: 'click'
            functionBefore: function(origin, continueTooltip) {
                continueTooltip();      
                $.ajax({
                    type: 'GET',
                    url: '/ajax/platform.php',
                    data: {variable1: variable1, variable2: variable2},
                    success: function(data) {
                        origin.tooltipster('content', data).data('ajax', 'cached');
                        $("#input1").click(function(d) {
                                d.preventDefault();
                                alert("It works !");
                        });
                    }
                });
            },
            theme: 'tooltipster-shadow'
        });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多