javascript 如何在javascript中获取gridview文本框控件ID?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21852729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the gridview textbox control ID in javascript?
提问by Manivel
I have ASP.NET Gridview and Textbox control in it. Now I want to get the Textbox ID in java script. I had already referred this question in stack overflow but I couldn't get the exact answer.
我有 ASP.NET Gridview 和 Textbox 控件。现在我想在 java 脚本中获取文本框 ID。我已经在堆栈溢出中提到了这个问题,但我无法得到确切的答案。
My Gridview Template Code is
我的 Gridview 模板代码是
<asp:TemplateField HeaderText="Amt Recieve Now" ControlStyle-Width="100">
<ItemTemplate>
<asp:TextBox ID="txtAmountReceiveNow" runat="server" CssClass="textboxRight"
AutoPostBack="true" OnFocus= "GVtxtAmount()"
OnTextChanged="txtAmountReceiveNow_TextChange"
Text='<%#Eval("AMOUNT_RECEIVE_NOW")%>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
and Javascript code is as follows :
和 Javascript 代码如下:
function GVtxtAmount() {
var txtAmountReceive = document.getElementById(
'<%= ((GVMaintainReceiptMaster)Container)
.FindControl("txtAmountReceiveNow").ClientID %>');
var selection = txtAmountReceive.value.indexOf(".");
alert(selection);
};
GVMaintainReceiptMasteris ID of GridView
GVMaintainReceiptMaster是 GridView 的 ID
Help me to overcome this problem.
帮助我克服这个问题。
回答by raza rabbani
Try this
试试这个
function GVtxtAmount() {
var txtAmountReceive = $("input[id*=txtAmountReceiveNow]")
var selection = txtAmountReceive.value.indexOf(".");
alert(selection);
};
回答by Aftab Ahmed
You can't get text box in this way. Here is the work-around I hope it will help.
您无法以这种方式获取文本框。这是解决方法,我希望它会有所帮助。
function GVtxtAmount() {
var GVMaintainReceiptMaster = document.getElementById('<%= GVMaintainReceiptMaster.ClientID %>');
for (var rowId = 1; rowId < GVMaintainReceiptMaster.rows.length; rowId++) {
var txtbx = GVMaintainReceiptMaster.rows[rowId].cells[0].children[0];
alert(txtbx.value);
}
return false;
}