【问题标题】:jQuery selector in ajax successajax成功的jQuery选择器
【发布时间】:2012-01-21 12:17:36
【问题描述】:

脚本不会在 AJAX 中搜索新的 selement (span)。

var str = $(this).html();
            var re = new RegExp(t);

            $(this).html(str.replace(re, '<span id="sel" style="color: red">' + t + '</span>'));

            if (t != "")
            {
                $.ajax({
                    url: './ajax/translate.php',
                    type: 'POST',
                    data: 'text=' + t,
                    success: function(response) {
                        $("#sel").html("!!!!!");
                    }
                });
            }

文字变红了,但是经过AJAX后,并没有变成“!!!!!”...

我应该如何为这个跨度编写选择器?

更新: 我看到变量 t 在用替换刷新 $(this).html(...) 后变为空...

【问题讨论】:

  • 你能发布一个带有示例的 jsfiddle 吗?

标签: jquery ajax selector


【解决方案1】:

我注意到的一件事是 t 是空白的,这可能是您的 ajax 函数没有被调用并且最终没有附加 '!!!!' 的原因到str

演示:http://jsfiddle.net/X9pky/

【讨论】:

    猜你喜欢
    • 2013-01-02
    • 2014-04-17
    • 2021-12-28
    • 1970-01-01
    • 2013-12-13
    • 2013-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多