jQuery 如何在Jquery Mobile中定义文本区域的高度和宽度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11880823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to define the height and width of the text area in Jquery Mobile?
提问by Surya
Before entry, the input field is predefined size (two lines on the screen width)..:( Its not taking anything as I define in the rows and cols value.. Ex: Still the input feild is fixed...Showing no changes.
在输入之前,输入字段是预定义的大小(屏幕宽度上的两行)..:( 它没有采用我在行和列值中定义的任何内容.. 例如:仍然输入字段是固定的......显示没有变化.
Gradually, as we introduced the text, the height of the input field increases, to view the text introduced in its entirety.
渐渐地,随着我们引入文本,输入字段的高度增加,以查看完整引入的文本。
But what I need is to define my own height and width of the textfeild...And gradually feild should increase if the text entered is more.
但我需要的是定义我自己的文本字段的高度和宽度......如果输入的文本更多,字段应该逐渐增加。
Code I am using is:
我使用的代码是:
<div data-role="content">
<form method="post" name="login" data-ajax="false">
<label for="textarea"><h3><u>Add Comment</u> : </h3></label>
<textarea cols="8" rows="50" name="textarea" id="comment">
</textarea>
</form>
<div>
回答by Reinstate Monica Cellio
There's a couple of ways you can do this.
有几种方法可以做到这一点。
You can use the cols & rows attributes...
您可以使用 cols & rows 属性...
?$("textarea").??????attr("rows", 20)??????;
?$("textarea").??????attr("cols", 25)??????;
or set the width & height directly...
或者直接设置宽高...
?$("textarea").??????height(200);
?$("textarea").??????width(250);
I'd recomment giving the textarea an ID and using that as the selector, as the above will obviously affect all textarea elements on the page.
我建议给 textarea 一个 ID 并将其用作选择器,因为上述内容显然会影响页面上的所有 textarea 元素。
回答by Jawa the Hutt
If I need to preset the size of a textarea, I declare the size in the HTML itself:
如果我需要预设 textarea 的大小,我会在 HTML 本身中声明大小:
<textarea id="Summary" style="height:100px; width:250px"></textarea>
回答by samsquanch
This has been answered here: JQuery Mobile textarea: how does it use 'rows' attribute?
这已在此处得到解答:JQuery Mobile textarea: how do it use 'rows' 属性?
In short, add the !important flag to your css item.
简而言之,将 !important 标志添加到您的 css 项目中。
.custom_class {
height: auto !important; /* !important is used to force override. */
}
回答by Taker Wu
jQuery mobile will auto append the class ".ui-input-text" to textarea
then the height will be set to 50px (in my jQuery mobile version)
so we need to do is setting this in your CSS file:
jQuery mobile 会自动将类“.ui-input-text”附加到 textarea
然后高度将设置为 50px(在我的 jQuery mobile 版本中)
所以我们需要做的是在你的 CSS 文件中设置它:
textarea.ui-input-text { height: inherit }
and all done :)
一切都完成了:)