简体   繁体   English

如何:在按键上获取 textarea1 高度并将高度设置为 textarea2

[英]How to: On keypress get textarea1 height and set height to textarea2

I have 2 textareas (textarea1 and textarea2).我有 2 个文本区域(文本区域 1 和文本区域 2)。 On textarea1 im using an expander.在 textarea1 上使用扩展器。 As you type the textarea expands.当您键入时,文本区域会展开。 Now, what ever you type on the textarea1 is written on textarea2 but the second textarea doesn't expand.现在,您在 textarea1 上键入的内容都写在 textarea2 上,但第二个 textarea 并没有扩展。 I am looking something that would get the height from textarea1 as im typing and set it to textarea2.我正在寻找可以在输入时从 textarea1 获得高度并将其设置为 textarea2 的东西。 I would image it would be something like:我会想象它会是这样的:

$("#textarea1").bind("keyup keypress paste mouseup", function() {
    $('#textarea1').val().height== ('#textarea2').height??

or或者

$("#textarea1").bind("keyup keypress paste mouseup", function() {
    $('#textarea2').attr('height', $('#textarea1').val().height);

None of those work.这些都不起作用。

Thanks alot非常感谢

$("#textarea2").css("height", $("#textarea1").height() + "px");

That should work.那应该行得通。

$("#textarea1").bind("keyup keypress paste mouseup", function() {
    $('#textarea2').css('height', $('#textarea1').height());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM