做一个公司的网站应做哪些准备,住房城乡建设管理网站,3d建模培训学校,wordpress 商务主题背景#xff1a; 页面上加了一个div标签#xff0c;div标签下有一个textarea标签#xff0c;textarea的内容通过后台读取数据自动填充#xff0c;希望通过textarea的高度随着内容的增减#xff0c;自动调整#xff0c;在网上说通过设置textarea属性可以解决#xff0c;即…背景 页面上加了一个div标签div标签下有一个textarea标签textarea的内容通过后台读取数据自动填充希望通过textarea的高度随着内容的增减自动调整在网上说通过设置textarea属性可以解决即onpropertychangethis.style.posHeightthis.scrollHeight οnfοcusthis.style.posHeightthis.scrollHeight然而设置过后然并卵问题依旧继续网上找解决方案终于在https://segmentfault.com/q/1010000000095238网上找了一个解决方案这个页面有一段话如下1、加入标签2、div设置css属性目的是用于textarea相对于expandingArea绝对定位.expandingArea{position:relative;}3、设置textarea的css属性textarea{position:absolute;top:0;left:0height:100%;}通过这样的样式设置textArea的高度会始终等于expandingArea的高度要让textarea的高度变化也只需要调整expadingArea的高度即可。那么怎么样让expandingArea的高度变化随内容高度变化而变化呢答案就是这个pre4、设置pre的css属性pre{display:block;visibility:hidden;}pre以块形式存在并且不可见但是是占用空间的不像display:none;什么空间也不占。这时需要把textarea中的内容实实的同时到pre里的span标签中因为pre没有postion:absolute所以它的高度会一直影响expandingArea的高度。总结原理就是pre会随内容的高度变化而变化expandingArea的高度又随pre变化因为textarea的高度100%textarea的高度会随expandingArea变化只要同步textarea的内容到pre中就达到一个textarea随内容高度变化的目的了5、经过自己设置内容如下contentcontent其中content用实际从后台返回的结果填充。经测试方法可行。