大家好,我在Java Web项目中使用react和jquery来呈现动态网页。所以我想使用函数ReactDOMServer.renderToStaticMarkup(element)来检索与html元素相关的html节点,但是我收到了错误消息:
***Uncaught ReferenceError: ReactDOMServer is not defined***
我也在网上搜索以找到CDN ReactDOMServer来更正错误,但发生其他错误。 这是示例代码:
HTML文件
<!DOCTYPE html>
<html>
<head>
<title>ORION WAMBERT</title>
<style type="text/css">
body{
font-family: "comic sans ms";
}
</style>
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="react.development.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="react-dom.development.js"></script>
<script type="text/javascript" src="babel.min.js" charset="utf-8"></script>
<script type="text/babel" src="appReact.jsx">
</script>
</body>
</html>
JSX文件
class Button extends React.Component{
handleClick(e){
ReactDOM.render(<TextView text="HELLO WORLD"/>,$("#root").get(0));
}
render(){
return <button onClick={this.handleClick}>{this.props.value}</button>;
}
}
class TextView extends React.Component{
render(){
return <h3>{this.text}</h3>;
}
}
let element=<Button value="click me"/>;
$("#root").html(ReactDOMServer.renderToStaticMarkup(element));