我尝试在 Android 浏览器中运行来自http://facebook.github.io/react/docs的一些示例,但它们不起作用 - 页面为空。所有页面都由本地运行的 Django 开发 Web 服务器提供,并且工作正常,除了那些使用 React 的页面。完全相同的链接在笔记本电脑上工作正常。来自他们的文档“如果您想在触摸设备(即手机或平板电脑)上使用 React,只需调用React.initializeTouchEvents(true);
以打开它们。” 我认为在移动设备上运行应该没有问题。我在这里缺少一些陷阱吗?来源是:
<!DOCTYPE html>
<html>
<head>
<title>Hello React</title>
<script src="/static/phs/js/react.js"></script>
<script src="/static/phs/js/JSXTransformer.js"></script>
</head>
<body>
<div id="example"></div>
<div id="example1"></div>
<script type="text/jsx">
/** @jsx React.DOM */
React.initializeTouchEvents(true);
var HelloWorld = React.createClass({
render: function() {
return (
<p>
Hello, <input type="text" placeholder="Your name here" />!
It is {this.props.date.toTimeString()}
</p>
);
}
});
setInterval(function() {
React.renderComponent(
<HelloWorld date={new Date()} />,
document.getElementById('example')
);
}, 1000);
var LikeButton = React.createClass({
getInitialState: function() {
return {liked: false};
},
handleClick: function(event) {
this.setState({liked: !this.state.liked});
},
render: function() {
var text = this.state.liked ? 'like' : 'unlike';
return (
<p onClick={this.handleClick}>
You {text} this. Click to toggle.
</p>
);
}
});
React.renderComponent(
<LikeButton />,
document.getElementById('example1')
);
</script>
</body>
</html>