我今天开始学习react,并且仍然试图弄清楚这个庄严的东西,有人能帮助我并且分享一下这个简单的代码在react中会是什么样子吗?从js规则到react的转换对我来说仍然有点困难。
提前感谢,祝您度过愉快的一天/一夜。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<input type="text" id="inp1" /> + <input type="text" id="inp2" />
<div id="results">=</div>
<button onclick="myFunction()">Add</button>
<script>
myFunction = () => {
const num1 = parseInt(inp1.value);
const num2 = parseInt(inp2.value);
const res = num1 + num2;
document.getElementById("results").innerHTML =
"= The sum of " + num1 + " and " + num2 + " is: " + res;
};
</script>
</body>
</html>
1条答案
按热度按时间hi3rlvi21#