如何将网格中的文本框ID分配给javascript函数 [英] How To assign A Textbox Id which is in Grid to javascript Function

查看:56
本文介绍了如何将网格中的文本框ID分配给javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type=text/javascript;
google.load("elements", "1", {
    packages: "transliteration"
});
function onLoad() {
       var lang = document.getElementById("<%= hdnlang.ClientID %>").value;
       var options = {
           sourceLanguage: 'en',
           destinationLanguage: [lang],
           transliterationEnabled: true
       };
       var control = new google.elements.transliteration.TransliterationControl(options);
       var ids = ["textboxid"];
       control.makeTransliteratable(ids);
       control.showControl('translControl');
}




<td>
<telerik:RadGrid ID="gvSettings" AllowSorting="false" AllowPaging="false"  runat="server"

CssClass="grid tBorder" ShowFooter="false" AllowMultiRowSelection="false" AllowMultiRowEdit="false"

AllowFilteringByColumn="false" CellSpacing="0" CellPadding="0" AutoGenerateColumns="False"

Skin="" Width="99%" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Center"

AlternatingItemStyle-HorizontalAlign="Left" HorizontalAlign="Center">
<footerstyle cssclass="gridfooter" />
<HeaderStyle HorizontalAlign="Center" CssClass="gridHeader"></HeaderStyle>
<itemstyle horizontalalign="Left" cssclass="gridItem" height="30px"></itemstyle>
<pagerstyle mode="NumericPages" cssclass="gridpage" position="Bottom" />
<alternatingitemstyle horizontalalign="Left" cssclass="gridAltItem" height="30px">
</alternatingitemstyle>
<filteritemstyle cssclass="gridFliterItem" />
<SelectedItemStyle CssClass="gridSelectedItem" />
<commanditemstyle cssclass="gridCommandItem" />
<mastertableview>
<columns>
<telerik:gridtemplatecolumn headertext="Template Text" itemstyle-width="50%" uniquename="Text" xmlns:telerik="#unknown">
<itemtemplate>
<asp:TextBox ID="txtTemplateText" runat="server" />
</itemtemplate>
<itemstyle width="50%" />
</telerik:gridtemplatecolumn>
</columns>
<editformsettings>
<editcolumn filtercontrolalttext="Filter EditCommandColumn column">
</editcolumn>
</editformsettings>
</mastertableview>
<filtermenu enableimagesprites="False">
</filtermenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_">
</HeaderContextMenu>
</td>





我想将网格文本框ID(txtTemplateText)传递给Javascript函数

var ids = [textboxid ]。怎么做..



I want to pass the Grid Textbox id(txtTemplateText) to the Javascript Function
var ids = ["textboxid"]; how to do it..

推荐答案

您应该查看标记,以获取有关页面结构的线索。 Javascript只会在页面呈现后运行。



在ClientId等的情况下,它们是在运行时在telerik网格和页面或控件中生成的代码隐藏没有意识到它们。你可以找到它们但输出到javascript中并不是一件容易的事。



最好的方法是使用jQuery。它提供扩展功能并使JS变得更加容易:



如果查看呈现页面上的源代码,您将看到文本框的客户端ID可能结束类似于... _ gvSettings_txtTemplateText_0



你可以使用jQuery快速找到所有这些使用id contains(id * ='')选择器:

You should look at the markup for clues on how the page is structured. Javascript will only ever run after the page has been rendered.

In the case on ClientId's et al, They are generated at runtime in the telerik grid and the Page or Control codebehind is not made aware of them. You can find them but outputting this into javascript is no mean feat.

The best way would be to use jQuery. It offers extension functions and makes JS so much easier:

If you look at the source on the rendered page, you will see that the client id of the textboxes might end with something like ..._gvSettings_txtTemplateText_0

You can use jQuery to find all of these very quickly using the id contains (id*='') selector:
var textboxes =


输入[id * ='gvSettings_txtTemplateText']



结果在'textboxes'将是文本框元素的数组。



这里有一篇很好的文章从jQuery开始:

jQuery for Beginners [ ^ ]



一旦有了这些文本框,就可以使用jquery轻松添加一个函数:


The result in 'textboxes' will be an array of the textbox elements.

There is a good article for starting with jQuery here:
jQuery for Beginners[^]

Once you have these textboxes, adding a function to them is easy with jquery:

textboxes.change(function(){
    var textboxBeingChanged = this;

    var newVal = textboxBeingChanged.val(); 
});


这篇关于如何将网格中的文本框ID分配给javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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