如何在gridview内的文本框上实现Javascript? [英] How do I implement Javascript on a textbox inside a gridview?

查看:45
本文介绍了如何在gridview内的文本框上实现Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此javascript作为字段验证器

I use this javascript as a field validator

 <script type="text/javascript">
      //Function to allow only numbers to textbox
      function validate(key) {
          //getting key code of pressed key
          var keycode = (key.which) ? key.which : key.keyCode;
          var phn = document.getElementById('txtPhn');
          //comparing pressed keycodes
          if (!(keycode == 8 || keycode == 46) && (keycode < 48 || keycode > 57)) {
              return false;
          }
          else {
              //Condition to check textbox contains ten numbers or not
              if (phn.value.length < 10) {
                  return true;
              }
              else {
                  return false;
              }
          }
      }
</script>





并将该功能添加到文本框



and add the function to the textbox

<asp:TextBox ID="txtTotal" runat="server" Width="131px" BorderStyle="None" Height="18px" onkeypress="return validate(event)"></asp:TextBox>





但是,当控件在gridview内部时,



例如文本框在gridview内,我该如何调用onkeypress事件?



However, when the control is inside a gridview,

for example the textbox is inside the gridview, how do I call the onkeypress event?

推荐答案

参考:如何访问Gridview中的文本框值使用Javascript代码 [ ^ ]


这篇关于如何在gridview内的文本框上实现Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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