问题:当我尝试使用关于jsx代码的highlight.js时,消失了html标记。如何获取innerHTML中的原始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)}
)
}
});
$( '预编码')[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)}) } }); "
为什么消失html标记innerHTML的? 如何获取innerHTML中的原始html字符串?
我希望能源渲染后:
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>
)
}
});
感谢您的耐心:)
有一个愉快的一天!
的< and the >应该是实体 – epascarello