English 中文(简体)
在补充投入的同时,重新启用一个超文本投稿箱?
原标题:Stretching a HTML Input Box alongside additional input?

该网站有投入。 当用户进入数据和空间时,我像某个特定领域那样需要更长时间(宽)。

www.un.org/Depts/DGACM/index_spanish.htm 我怎么能够计算一下何时需要投入(type=“text)?? 一个浏览器的操作方式可能不利于所有浏览器。

www.un.org/Depts/DGACM/index_spanish.htm 是否可以计算出这样的东西,因此每个人都会根据每个浏览器内的审判和错误来计算? 我是否需要利用这一价值,用一刀子检查价值? EG.

$(".stretchInput").keyup( function(event) {
   var someValueAdjustedByTrialAndError = 30;
   var stretchPastLength = someValueAdjustedByTrialAndError;
   var stretchBy = 5;
   var baseWidth = 100;
   if ($(this).val().length > stretchPastLength ) {
      $(this).css( width ,(baseWidth + ($(this).val().length - stretchPastLength ) * stretchBy ) +  px );
   } else {
      $(this).css( width ,  );
   }
});
最佳回答

[签名]

在网页和<代码>keyup内放置一个隐藏的<代码><span>要素 页: 1 2. 更新投入领域,以适应您的时代。

<<>Html>:

<span style="display:none"></span>
<input type="text" style="width:100px"; />

注<代码>min-width 用于防止 w缩到低于一定价值的输入要素的价值。

www.un.org/Depts/DGACM/index_spanish.htm 学历:

$( input ).keyup(function() {
    var $span = $( span );
    var $this = $(this);
    $span.text($this.val()); 
    $this.width($span.width());
});
问题回答

Solution for TextAreas

Description

This sounds like you want a auto growing textarea like on facebook. If so why reinvent the wheel ? I encorage you to use the wonderful Elasting jQuery Plugin.

Elastic makes your textareas grow and shrink to fit it’s content. It was inspired by the auto growing textareas on Facebook. The major difference between Elastic and it’s competitors is it’s weight.

More Information

Solution for Text Inputs

在此,我对<编码>输入要素的解决办法。

问题是,每个字体的毛.不是 偶然/em>。

如果你选择信使,你可以做到完美。

Sample

www.un.org/Depts/DGACM/index_spanish.htm Html

<input class="stretchInput" style="font-family: courier"/>

jQuery

var initialWidth = $(".stretchInput").width();
$(".stretchInput").keyup( function(event) {
   var charWidth = 8.5;
   var width = $(this).val().length*charWidth;
   if ($(this).width() < width)
   {
       $(this).width(width);
   } else {
       $(this).width(initialWidth );
   }
});

Check out my jsFiddle





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.