html()返回带有标记的html

Javascript .html() returns html with tags

本文关键字:html 返回      更新时间:2023-09-26

在我的ROR应用程序中,

在我的控制器中

1-@linkhtml="Please contact #{ActionController::Base.helpers.link_to 'support', "www.blahblah.com"}."

它在..中调用一个js文件create.js。。

2-$(#linkhtml).html('<%= @linkhtml %>')

和在erb文件中

3-<div id=linkhtml></div>

返回

<a href="www.blahblah.com/">support</a>

如何使其返回链接的"支持"?

编辑:

我应该在1中使用strip_tag或者在2中使用something()而不是html()或者以其他方式显示它,而不是在3 中的div中显示"id=linkhtml"

$(#linkhtml).text()

这将返回没有HTML标签的纯文本

参考:http://api.jquery.com/text/