开发者

Not working Javascript in any browser except IE

I have following code..

  <html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
  <title>Automatic Resize TextBox</title>
  <script type="text/javascript">
  function setHeight(txtdesc) {
    txtdesc.style.height = txtdesc.scrollHeight + "px";
  }
  </script>
  </head>
  <body>
  <form id="form1" runat="server">
  <div>
  <asp:TextBox ID="txtDesc" runat= "server" TextMode="MultiLine"  Onkeyup="setHeight(this);" onkeydown="setHeight(this);" />
   </div>
   </form>
   </body>
   </html>

This is a javascript for Resize the Textbox while writing in text box.means if textbox will fill completely then it will be expand 开发者_如何学Goautomatically but if we remove the textbox then the textbox will be collapsed...its working fine in IE but not in other browser plz help me....


http://jsfiddle.net/eT6tR/

I have found this working in Chrome and FF. If you still facing issue. write in details and paste client side code here means HTML+JS.


The problem you're facing is that in IE the scrollHeight is calculated based on just the contents of the text area and in other browsers it is based on the available content space. This means that setting the CSS height will increase the scrollHeight and prevent it from shrinking back down.

This question has come up many times and it looks like the best answer people have come up with is to perform the complicated task of calculating how many rows there would be based on the text content. See this SO question and many others by searching.

Here is an example you can look at using jQuery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜