react版本问题


  • 0

    @胡子大哈

    react用的哪个版本?用不用引入react-dom.js?

    return '<html></html>'和return (<html></html)都报错?

    <div id="wrapper"></div>
    
    	<script type="text/jsx">
    		class LikeButton{
    			render () {
    				return (
    					<button id="like-btn">
    						<span className="like-text">赞</span>
    						<span></span>
    					</button>
    				)
    			}
    		}
    		const wrapper = document.querySelector('.wrapper')
    		cosnt likeButton = new LikeButton()
    		wrapper.innerHTML = likeButton.render()
    
    		const likeButton2 = new LikeButton()
    		wrapper.innerHTML += likeButton2.render()
    

    页面上什么都没有?


  • 0
    administrators

    @labike

    小书的例子是 15 版本的。你可以贴出你的完整代码和错误信息吗?


  • 0

    @胡子大哈

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8"/>
    	<title>Document</title>
    	<script src="https://cdn.bootcss.com/react/15.5.0/react.js"></script>
    	<script src="https://cdn.bootcss.com/react/15.5.0/react-dom.js"></script>
    </head>
    <body>
    	<div id="wrapper"></div>
    
    	<script type="text/jsx">
    		class LikeButton{
    			render () {
    				return (
    					<button id="like-btn">
    						<span className="like-text">赞</span>
    						<span></span>
    					</button>
    				)
    			}
    		}
    		const wrapper = document.querySelector('#wrapper')
    		const likeButton = new LikeButton()
    		wrapper.innerHTML = likeButton.render()
    
    		const likeButton2 = new LikeButton()
    		wrapper.innerHTML += likeButton2.render()
    	</script>
    </body>
    </html>
    

    控制台没有错误!

    return()改为return ' '0_1494903837072_2017-05-16_110309.png

    控制台也不报错


  • 0
    administrators

    @labike 你的 id='wrapper' 改成 class='wrapper',请按照书上的代码来哈


  • 0

    此回复已被删除!

登录后回复
 

与 ScriptOJ 的连接断开,我们正在尝试重连,请耐心等待