【发布时间】:2018-12-28 08:13:20
【问题描述】:
我知道 React 创建了一个虚拟 DOM 并比较了差异,然后只更新了真实 DOM 的实际元素,但是如果我手动更改它,那如何更有效呢?通过getElementById 还是使用jQuery 函数?
<!DOCTYPE html>
<html>
<body>
<form>
Select your favorite browser:
<select id="myList" onchange="myFunction()">
<option></option>
<option>Google Chrome</option>
<option>Firefox</option>
<option>Internet Explorer</option>
<option>Safari</option>
<option>Opera</option>
</select>
<p>Your favorite browser is: <input type="text" id="demo" size="20"></p>
</form>
<script>
function myFunction() {
var mylist = document.getElementById("myList");
document.getElementById("demo").value = mylist.options[mylist.selectedIndex].text;
}
</script>
</body>
</html>
【问题讨论】:
-
你的代码和你的问题有什么关系?
标签: javascript reactjs virtual-dom