javascript - jQuery - 如何在引号中包围 Ajax 加载的元素?

标签 javascript jquery html ajax

我有一个推荐 slider 。通过 ajax .load() 方法从同一站点上的另一个页面提取推荐。我正在尝试将收到的推荐用引号括起来。 (例如:这是一份推荐。将是“这是一份推荐。”)。但是,我的代码无法运行。

这是应该添加引号的函数:

function quotations(){
$(this).prepend('"').append('"');
};

这是 ajax 函数(推荐从/?page=testimonials&gridID=1 .cfgThemeGridGenericContent 加载):

$(function($){
$("#slide1").load("/?page=testimonials&gridID=1 .cfgThemeGridGenericContent", function() {shorten('slide1'); quotations();})
};

html结构如下:

<div class="slides" id="slide1">
This is the testimonial text.
</div>

您看到的 Short() 函数只是一个确保推荐不会太长的函数。我已经确认它有效。如果我需要添加它,请告诉我。

为什么我的推荐没有被引用?

最佳答案

只需使用CSS:

div.slides::before,
div.slides::after {
    content: '"';
}

至于“为什么它不起作用”我怀疑这可能取决于 quotations() 中的 $(this) 是什么 函数。

关于javascript - jQuery - 如何在引号中包围 Ajax 加载的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27007699/

相关文章:

javascript - 使用什么事件来触发将 JSON 内容插入到现有 HTML 标记中?

javascript - 在 iframe 中获取 innerdiv 的 id

html - 为什么 div 不能很好地居中?

javascript - 当 image.src 有时间标签时更新 Canvas 图像

javascript - 使用 Jquery 显示数组中的先前项目

javascript - 如何从 JQuery Dialog 调用 C# 按钮事件

javascript - “*[attribute^="string""如何/为什么是有效的查询选择器?(JS 错误?)

javascript - 将 JS 函数返回的 url 传递到 href

jquery - Adobe Spry 与 JQuery 相比有多好以及什么是观点

javascript - 如何计算自定义滚动条的位置?