本文介绍了调整只读文本框的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好, 我在.ascx页面上有一个文本框。 textbox是pageload时的字段。文本框是只读的。现在我想要文本框的大小根据其中的文本。怎么做? 我用以下java脚本: < script type =text / javascript> 函数setHeight(txtdesc){ txtdesc.style.height = txtdesc.scrollHeight +px; } < / script> 以下文本框 < asp:TextBox ID = suggText runat = server OnTextChanged = setHeight(this) CommandArgument = <% #Container.DataItemIndex %> 文本 =' <%#DataBinder.Eval(Container.DataItem, suggetion)%> ' 字体大小 = 更小 TextMode = MultiLine 已启用 = 错误 OnCommand = txtSuggestion_Command 高度 = 20px ReadOnly = True > < / asp:TextBox > 但它会给出错误 ' ASP.controls_sugge stions_ascx'不包含定义 ' setHeight'且没有扩展方法' setHeight'接受类型为' ASP.controls_suggestions_ascx'(你错过了使用指令或汇编参考?) 请帮助 我尝试过: 我使用以下java脚本: < script type =text / javascript> function setHeight(txtdesc){ txtdesc.style.height = txtdesc.scrollHeight +px; } < / script> $ b这个以下文本框的$ b < asp:TextBox ID = suggText runat = server OnTextChanged = setHeight(this) CommandArgument = <% #Container.DataItemIndex %> 文字 =' <%#DataBinder.Eval(Container.DataItem, suggetion)%> ' 字体大小 = 更小 TextMode = MultiLine 已启用 = False OnCommand = txtSuggestion_Command 高度 = 20px ReadOnly = 真 > < / asp:TextBox > ,但它给出了错误 ' ASP.controls_suggestions_ascx'不包含的定义 ' setHeight',没有扩展方法' setHeight'接受类型' ASP的第一个参数。可以找到controls_suggestions_ascx'(您是否缺少使用指令或汇编参考?) 请帮助解决方案 您正尝试从服务器端事件( TextChanged )调用客户端方法( setHeight )。使用 onchange 属性: < asp:TextBox ID = suggText runat = server onchange = setHeight(this ) ... 或从Javascript连接事件处理程序: var element = document .querySelector( textarea [name = suggText]); element.addEventListener( 更改,函数(){ setHeight( this ); }); Hello, I having a textbox on .ascx page. textbox is field at the time of pageload. textbox is readonly. now I want size of textbox as per the text in it. how to do this?I use following java script: <script type="text/javascript">function setHeight(txtdesc) {txtdesc.style.height = txtdesc.scrollHeight + "px";}</script>for this following textbox<asp:TextBox ID="suggText" runat="server" OnTextChanged="setHeight(this)" CommandArgument="<%#Container.DataItemIndex %>" Text='<%# DataBinder.Eval(Container.DataItem,"suggetion") %>' Font-Size="Smaller" TextMode="MultiLine" Enabled="False" OnCommand="txtSuggestion_Command" Height="20px" ReadOnly="True"></asp:TextBox>but it gives error that'ASP.controls_suggestions_ascx' does not contain a definition for 'setHeight' and no extension method 'setHeight' accepting a first argument of type 'ASP.controls_suggestions_ascx' could be found (are you missing a using directive or an assembly reference?)please helpWhat I have tried:I use following java script: <script type="text/javascript">function setHeight(txtdesc) {txtdesc.style.height = txtdesc.scrollHeight + "px";}</script>for this following textbox<asp:TextBox ID="suggText" runat="server" OnTextChanged="setHeight(this)" CommandArgument="<%#Container.DataItemIndex %>" Text='<%# DataBinder.Eval(Container.DataItem,"suggetion") %>' Font-Size="Smaller" TextMode="MultiLine" Enabled="False" OnCommand="txtSuggestion_Command" Height="20px" ReadOnly="True"></asp:TextBox>but it gives error that'ASP.controls_suggestions_ascx' does not contain a definition for 'setHeight' and no extension method 'setHeight' accepting a first argument of type 'ASP.controls_suggestions_ascx' could be found (are you missing a using directive or an assembly reference?)please help 解决方案 You're trying to call a client-side method (setHeight) from a server-side event (TextChanged). Either use the onchange attribute:<asp:TextBox ID="suggText" runat="server" onchange="setHeight(this)" ...or wire the event-handler up from Javascript:var element = document.querySelector("textarea[name=suggText]");element.addEventListener("change", function(){ setHeight(this);}); 这篇关于调整只读文本框的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-31 08:18