本文介绍了渲染javascript函数返回内部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 .jade 文件中使用此代码,在 for 循环内使用对象的值迭代和呈现 html:
I am using this code in a .jade file, inside a for loop to iterate and render html with a object's values:
- var linkExist = function(i){
- if (result[i]){
- var html = ',follow on ' + i + ': <a href="' + result[i] + '" target="_blank">' + result[i].split("http://")[1] + '</a>';
- return html;
- };
- }
#{linkExist('Twitter')}
#{linkExist('GitHub')}
它添加了额外的注释,并在 >
之前渲染了一个额外的 <
,就像
It adds extra comments and renders a extra <
before na d a >
after, like
<
,follow on Twitter:
<a href="http://twitter.com/user" target="_blank">twitter.com/user</a>
>
<!--,follow on Twitter: <a href="http://twitter.com/user" target="_blank"-->
twitter.com/user
>
<
,follow on GitHub:
<a href="http://github.com/user" target="_blank">github.com/user</a>
>
<!--,follow on GitHub: <a href="http://github.com/user" target="_blank"-->
github.com/user
>
顺便说一句,如果我使用
btw, if I use
=linkExist('Twitter')
or
| #{linkExist('Twitter')}
它将 html 呈现为文本,但内容正确.(但作为文本,而不是 html)
It renders html as text, but the correct content. (but as text, not html)
推荐答案
知道了,
jade 会自动转义 html.为了避免这种情况,可以使用 !=
.
jade escapes the html automatically. To avoid that one can use !=
.
所以我改为:
- var linkExist = function(i){
- if (result[i]){
- var html = ' ,follow on ' + i + ': <a href="' + result[i] + '" target="_blank">' + result[i].split("http://")[1] + '</a>';
- return html;
- };
- }
!= linkExist('Twitter')
!= linkExist('GitHub')
这篇关于渲染javascript函数返回内部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!