这是一个简单的网页。为什么浏览器调整大小时textarea的宽度不会改变?JavaScript不影响HTML元素
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function resize() {
document.getElementById("main").style.width=window.innerWidth;
}
window.onresize = resize;
window.onload = resize;
</script>
</head>
<body style="margin:0; padding:0;">
<textarea id="main" style="margin:0; padding:0; border:0;" >It was a dark and stormy night, and the rain came pouring down... </textarea>
</body>
</html>
@Phil op为的onload运行它... ...这怎么不是呢?如果只有我们可以减少评论。 – epascarello
@epascarello oops。不建议阅读脱机问题:) – Phil
感谢大家的正确答案。这东西我有点生疏。 – WhiteHotLoveTiger