asp.net – 如何将服务器控件的实际客户端ID传递给javascript函数?

栏目: ASP.NET · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/1362338/how-do-i-pass-a-server-controls-actual-client-id-to-a-javascript-function

我的网页中有以下文本框服务器控件:

<asp:TextBox ID="txtZip" runat="server" onchange="ZipCode_OnChange(this, <%= txtZip.ClientId %>, txtCity, txtState);/">

页面呈现时,它包含以下内容:

<input name="txtZip" type="text" id="txtZip" onchange="ZipCode_OnChange(this, <%= txtZip.ClientId %>, txtCity, txtState);" />

我正在尝试将文本框的客户端ID作为第二个参数传递给此Javascript函数:

function ZipCode_OnChange(txtZipCode, ClientId) {
    var ret;
    ret = WebService.GetCityAndState(txtZipCode.value, OnComplete1, OnError, ClientId);
}

如何在服务器上获取它,评估texbox的控件并将该文字字符串传递给Javascript函数?

把<

%= txtZip.ClientId%>单引号之间,如下所示:

'<%= txtZip.ClientId %>'


<asp:TextBox ID="txtZip" runat="server" onchange="ZipCode_OnChange(this, '<%= txtZip.ClientId %>', txtCity, txtState);" />

更新

请查看这篇文章: http://www.jagregory.com/writings/how-to-use-clientids-in-javascript-without-the-ugliness/

我也喜欢 this answer

翻译自:https://stackoverflow.com/questions/1362338/how-do-i-pass-a-server-controls-actual-client-id-to-a-javascript-function


以上所述就是小编给大家介绍的《asp.net – 如何将服务器控件的实际客户端ID传递给javascript函数?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

Learning PHP, MySQL, JavaScript, and CSS

Learning PHP, MySQL, JavaScript, and CSS

Robin Nixon / O'Reilly Media / 2012-9-3 / USD 39.99

If you're familiar with HTML, you can quickly learn how to build interactive, data-driven websites with the powerful combination of PHP, MySQL, and JavaScript - the top technologies for creating moder......一起来看看 《Learning PHP, MySQL, JavaScript, and CSS》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具