如何使用 jquery 在文本之间插入分隔符?
更新
以下是旧 CMS 的输出。 我想在“Klikk her om du er privatkunde!”之后插入一个中断标签。 '。
从这,
<TR>
<TD CLASS="td-main" COLSPAN="6">
<A HREF="link to some page">Other link here.</A>
<A HREF="link to some page">There could be other link, but may be.</A>
</TD>
</TR>
...
<TR>
<TD CLASS="td-main" COLSPAN="6">
<A HREF="edit-8.asp?CustType=1">Klikk her om du er privatkunde</A>!
<A HREF="edit-8.asp?CustType=2">Klikk her om du er bedriftskunde</A>!
</TD>
</TR>
...
到这。
...
...
...
<TR>
<TD CLASS="td-main" COLSPAN="6">
<A HREF="edit-8.asp?CustType=1">Klikk her om du er privatkunde</A>!
<br />
<A HREF="edit-8.asp?CustType=2">Klikk her om du er bedriftskunde</A>!
</TD>
</TR>
谁能告诉我该怎么做吗?
提前致谢。
我想到的是这个,但它不起作用。
if(location.pathname.indexOf('edit-8') > 0){
$('td[value|=Klikk her om du er privatkunde!]').replaceWith('Klikk her om
du er privatkunde!<br />')
}
Updated
The following is an output from a old CMS.
I would like to insert a break tag after 'Klikk her om du er privatkunde!
'.
From this,
<TR>
<TD CLASS="td-main" COLSPAN="6">
<A HREF="link to some page">Other link here.</A>
<A HREF="link to some page">There could be other link, but may be.</A>
</TD>
</TR>
...
<TR>
<TD CLASS="td-main" COLSPAN="6">
<A HREF="edit-8.asp?CustType=1">Klikk her om du er privatkunde</A>!
<A HREF="edit-8.asp?CustType=2">Klikk her om du er bedriftskunde</A>!
</TD>
</TR>
...
to this.
...
...
...
<TR>
<TD CLASS="td-main" COLSPAN="6">
<A HREF="edit-8.asp?CustType=1">Klikk her om du er privatkunde</A>!
<br />
<A HREF="edit-8.asp?CustType=2">Klikk her om du er bedriftskunde</A>!
</TD>
</TR>
Could anyone tell me how to do it please?
Thanks in advance.
What I came up is this, but it does not work.
if(location.pathname.indexOf('edit-8') > 0){
$('td[value|=Klikk her om du er privatkunde!]').replaceWith('Klikk her om
du er privatkunde!<br />')
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果通过
href
选择是唯一的,则可以使用.before()
和一个 attribute-equals 选择器:If selecting by the
href
is unique, you can use.before()
and an attribute-equals selector for this:下面的 jQuery 链执行此操作:
标记。
。
标记之前插入
元素。我原本只是打算在包含匹配文本的
之后直接插入
标记,但如果我这样做,它就会插入!
之前的换行符位于该标记之外。意见。这真的很奇怪。如果该文本发生更改会发生什么?我不想维护该网站。
The jQuery chain below does this:
<a>
tag with the text 'Klikk her om du er privatkunde' inside of it.<a>
following it.<br>
element before the 2nd<a>
tag.I was originally just going to insert the
<br>
tag directly after the<a>
which contained the matching text, but if I did that, it would have inserted the line break before the!
which was outside of that tag.Opinion. This is really wonky. What happens if that text gets changed? I wouldn't want to maintain that website.