Onkeypress javascript无法在选项卡面板中工作 [英] Onkeypress javascript not working in tab panel

查看:70
本文介绍了Onkeypress javascript无法在选项卡面板中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在选项卡面板中有texbox,我想计算在文本框onkeypress中输入字符。但是当文本框位于选项卡面板内时,javascript无法正常工作。



我尝试了什么:



这是我的代码:



i have texbox inside tab panel and i want to count enter characters in textbox onkeypress. but javascript not working when textbox are inside the tab panel.

What I have tried:

here is my code:

  <script type="text/javascript">
function countChars(countfrom,displayto) {
  var len = document.getElementById(countfrom).value.length;
  document.getElementById(displayto).innerHTML = len;
}
    </script>







<ajax:TabContainer ID="TabContainer1" runat="server" CssClass="ajax__tab_red-theme"
                   Width="100%" ActiveTabIndex="0">
                   <ajax:TabPanel ID="tbpnlPhotos" runat="server">
                       <HeaderTemplate>
                            Student
                       </HeaderTemplate>
                       <ContentTemplate>

  <table width="100%">
                            <tr>
                       <td align="right" style="font-size: small">
                           <span id="charcount" style="color:red">0</span> characters entered.
                       </td>
                       </tr>
                           <tr>
                           <td align="center">
                             <asp:TextBox ID="txtMessage" onkeyup="countChars('txtMessage','charcount');" onkeydown="countChars('txtMessage','charcount');"
                               onmouseout="countChars('txtMessage','charcount');" runat="server" Width="95%"
                               placeholder="Message........" TextMode="MultiLine" Height="220px" MaxLength="2"
                               BorderColor="Blue"></asp:TextBox>
                           </td>
                           </tr>
                           </table>

                           <br />
                           <br />
                       </ContentTemplate>
                   </ajax:TabPanel>
  </ajax:TabContainer>

推荐答案

试试



try

<span id="charcount" style="color:red">0</span> characters entered.
      <asp:TextBox ID="txtMessage" onkeyup="countChars();" onkeydown="countChars();"
                             onmouseout="countChars();" runat="server" Width="95%"
                             placeholder="Message........" TextMode="MultiLine" Height="220px" MaxLength="2"
                             BorderColor="Blue"></asp:TextBox>







function countChars() {
          var textBoxClientID = '<%= txtMessage.ClientID%>'
          var len = document.getElementById(textBoxClientID).value.length;
          document.getElementById('charcount').innerHTML = len;
      }


这篇关于Onkeypress javascript无法在选项卡面板中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆