【发布时间】:2015-01-12 21:55:37
【问题描述】:
我正在使用 jquery 在锚点之后插入内容。例如,如果我有以下内容:
<p>this is an example sentence with a link coming up (Here's the <a href='#' class='insertpoint'>link content</a>). More text may or may not follow here.</p>
使用以下内容:
$("a.insertpoint").click(function() {
var mapDiv = $("<div class='map' id='testmap'><img src='graphics/loading.gif'></div>");
mapDiv.insertAfter($(this));
});
问题是一些链接后面有括号/大括号,这会为新的 div 造成难看的拆分。有没有什么好的方法可以查看链接后面是否有空格或段落结尾,如果没有,移动多少个字符直到到达空格?
【问题讨论】:
-
您应该发布更多代码,因为很难说出您在做什么,例如,您如何获得
$(this),它来自哪里? -
抱歉,我通常使用 $(this) 作为对单击的锚点的引用,并认为这很明显并且可以保持问题简洁。我现在可以看到混乱了,我已经编辑了要包含的问题。
标签: javascript jquery html css