如何使用JavaScript获取网格内的文本框的客户端ID?

时间:2017-05-14 06:37:59

标签: javascript asp.net

  

我有一个可编辑的Gridview(每行包含7个可编辑的字段/文本框),其中我有一个文本框,我是   调用JS函数,但如果文本框我没有得到客户端ID   在Grideview里面有什么办法吗?   GEIDVIEW - > GRID

  <asp:TemplateField>  <EditItemTemplate>
<asp:TextBox ID="txCTFact" runat="server" Text='<%# Eval("CT_Factor") %>' Width="50px" onchange="validateCTfactor(this);" />  
</EditItemTemplate>
 </asp:TemplateField>
  

JS本地我是通过

来做的
text = document.getElementById('GridSubMeter_' + v + '_txCTFact').value;
  

但是在不同的浏览器中,它会获得不同的客户端ID   通用方式。

 function validateCTfactor(val) {
            var v = val.id.split('_')[1];
            var text = document.getElementById('GridSubMeter_' + v + '_txCTFact').value;
            var re = new RegExp("^[0-9]+(\.[0-9]{1,1})?$");
            if (re.test(text)) {
                return true;
            }
            else {
                alert("Required Field with Only numbers allowed with 1 decimal place in CT Factor");
                return false;
            }
        }

1 个答案:

答案 0 :(得分:0)

import Ember from 'ember';
import applicationAdapter from './application';

export default applicationAdapter.extend({
  findRecord: function(store, type, id, snapshot) {
    if (snapshot.adapterOptions)) {
      let url = this.buildURL(type.modelName, id, snapshot, 'findRecord');
      let query = {
        include: Ember.get(snapshot.adapterOptions, 'include')
      };
      return this.ajax(url, 'GET', { data: query });
    } else {
      return this._super(...arguments);
    }
  }
});

您可以通过 function validateCTfactor(val) { var text = val.value; var re = new RegExp("^[0-9]+(\.[0-9]{1,1})?$"); if (re.test(text)) { return true; } else { alert("Required Field with Only numbers allowed with 1 decimal place in CT Factor"); return false; } } 直接获取文本框的值。不需要val.value

获取网格中每个文本框的ID:

id