[英]How to get the original html string in innerHTML?
问题:当我尝试使用关于jsx代码的Highlight.js时,请消失html标签。
原始资料:
<pre>
<code class="javascript">
const { Link } = ReactRouter;
App.QnAChild = React.createClass({
mixins: [Mixins.Accounts, Mixins.Utils],
render() {
let name = "";
if (this.props.user && this.props.user.name) {
name = this.props.user.name;
}
return (
<tr>
<td>
{this.props.index + 1}
</td>
<td>
<Link to={`/qna/${ this.props._id }`}
className="title-link"> {this.props.title}
</Link>
</td>
<td>
<Link to="">
{name}
</Link>
</td>
<td>
{this.momentKoreanDate(this.props.createdAt, 5)}
</td>
</tr>
)
}
});
</code>
</pre>
渲染源之后:
const { Link } = ReactRouter;
App.QnAChild = React.createClass({
mixins: [Mixins.Accounts, Mixins.Utils],
render() {
let name = "";
if (this.props.user && this.props.user.name) {
name = this.props.user.name;
}
return (
{this.props.index + 1}
{this.props.title}
{name}
{this.momentKoreanDate(this.props.createdAt, 5)}
)
}
});
$('pre code')[0] .innerHTML:
"const { Link } = ReactRouter; App.QnAChild = React.createClass({ mixins: [Mixins.Accounts, Mixins.Utils], render() { let name = ""; if (this.props.user && this.props.user.name) { name = this.props.user.name; } return ( {this.props.index + 1} <link to="{`/qna/${" this.props._id="" }`}="" classname="title-link"> {this.props.title} <link to=""> {name} {this.momentKoreanDate(this.props.createdAt, 5)} ) } }); "
为什么消失innerHTML中的html标签? 如何在innerHTML中获取原始的html字符串?
我希望在render之后获得资源:
const { Link } = ReactRouter;
App.QnAChild = React.createClass({
mixins: [Mixins.Accounts, Mixins.Utils],
render() {
let name = "";
if (this.props.user && this.props.user.name) {
name = this.props.user.name;
}
return (
<tr>
<td>
{this.props.index + 1}
</td>
<td>
<Link to={`/qna/${ this.props._id }`}
className="title-link"> {this.props.title}
</Link>
</td>
<td>
<Link to="">
{name}
</Link>
</td>
<td>
{this.momentKoreanDate(this.props.createdAt, 5)}
</td>
</tr>
)
}
});
谢谢您的耐心:)
祝你今天愉快!
"<" = < (lower then)
">" = > (greater then)
<pre> <code class="javascript"> const { Link } = ReactRouter; App.QnAChild = React.createClass({ mixins: [Mixins.Accounts, Mixins.Utils], render() { let name = ""; if (this.props.user && this.props.user.name) { name = this.props.user.name; } return ( <tr> <td> {this.props.index + 1} </td> <td> <Link to={`/qna/${ this.props._id }`} className="title-link"> {this.props.title} </Link> </td> <td> <Link to=""> {name} </Link> </td> <td> {this.momentKoreanDate(this.props.createdAt, 5)} </td> </tr> ) } }); </code> </pre>
您应该将代码存储在变量中:
var myCode = "<html>";
var processed = yourProcessor(myCode);
$('pre code').innerHTML = processed;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.