简体   繁体   English

如何将链接作为类名的跨度转换为<a href=“”>链接</a>

[英]how to transform a span with link as classname to an <a href=“”> Link

Hello Stackoverflow Community, 您好Stackoverflow社区,

I am getting an HTML output from an expression from angularjs. 我正在从angularjs的表达式中获取HTML输出。 In this angularjs expression {{html}}, I get some HTML code blocks like this. 在这个angularjs表达式{{html}}中,我得到了一些这样的HTML代码块。

<p>sometext ....<span class="externallink::https://www.siv.archives-nationales.culture.gouv.fr/siv/IR/FRAN_IR_054007 foreground-blue underline-1  ">Online-Findbuch</span>...some text</p>

Now I need to transform it to something I can work with. 现在,我需要将其转换为可以使用的东西。 A simple working link. 一个简单的工作链接。 For example. 例如。

<p>some text ....<a class="foreground-blue underline-1" href="https://www.siv.archives-nationales.culture.gouv.fr/siv/IR/FRAN_IR_054007">Online-Findbuch</a>...some text </p>

So as you can see, there are several problems to solve. 如您所见,有几个问题需要解决。 How to read and transform the span with the class "externallink::" to an Link with the added address. 如何使用类“ externallink ::”读取跨度并将其转换为具有添加地址的链接。 Leave the class names without the "externallink::" as a class name and transform the "Online-Findbuch" span name to a link name. 保留没有“ externallink ::”作为类名的类名,然后将“ Online-Findbuch”跨度名称转换为链接名。

Thank you for the help. 感谢您的帮助。

While your question is really unclear, trying whatever can be understood from that: 尽管您的问题确实不清楚,但可以尝试从中理解的任何方法:

There can be many methods to do, this is one using jQuery 可以有很多方法可以做,这是使用jQuery的一种

var span = $('<span class="externallink::https://www.siv.archives- 
nationales.culture.gouv.fr/siv/IR/FRAN_IR_054007 foreground-blue underline-1  
">Online-Findbuch</span>')

var spanClass = span[0].classList[0];

var aHref = spanClass.replace('externallink::', '');

var a = $("<a>");

a.attr('href', aHref);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM