for循环
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
<script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<div id="app"></div>
<script type="text/babel">
class Table extends React.Component{
constructor(props){
super(props)
this.state={
num:9
}
}
render(){
const arr=[]
for(let i=1;i<=this.state.num;i++)
{ const item=[]
for(let j=1;j<=i;j++){
item.push(<td key={j}>{i}*{j}={i*j} </td>)
}
arr.push(<tr>{item}</tr>)
}
return <div>{arr}</div>
}
}
ReactDOM.render(
<Table/>,
document.getElementById('app')
)
</script>
</body>
</html>
map循环
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
<script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<style>
span{
margin-right: 20px;
}
</style>
<body>
<div id="app">
</div>
<script type="text/babel">
function Table (props){
const list=props.number
return <table>{list.map((n)=>{
return <tr>{list.map((m)=>{
return n<m? null:<td>{n}*{m}={m*n}<span></span></td>
})}</tr>
})}</table>
}
const num=[1,2,3,4,5,6,7,8,9]
ReactDOM.render(
<Table number={num}/>,
document.getElementById('app')
)
</script>
</body>
</html>
别忘了引入React文件幺!!!!