获取 javascript 函数中 asp.button 函数的属性

发布于 2024-12-04 02:23:36 字数 99 浏览 1 评论 0原文

我想知道如何从 javascript 函数获取 asp:Button 的属性。

具体来说,我希望能够测试 javascript 函数中是否启用了特定的 aspx 按钮。

I would like to know how I can get the properties of an asp:Button from a javascript function.

Specifically I want to be able to test whether a specific aspx button is enabled or not in a javascript function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那支青花 2024-12-11 02:23:36

一旦知道 的客户端 ID,您就可以使用 document.getElementById 函数来获取其 DOM 对象的引用并获取您想要的其他属性。有兴趣.
示例:

aspx 标记中的某些位置:

<asp:Button id="button1" runat="server" Text="Click Me"/>

在 javascript 中:

<script type="text/javascript">
    //button1 is the ID of asp:Button
    var objButton = document.getElementById('<%=button1.ClientID');
</script>

Once you know the client ID of the <asp:Button /> you can use document.getElementById function to get the reference of it's DOM object and get other properties you are interested in.
An example:

Some where in aspx mark up:

<asp:Button id="button1" runat="server" Text="Click Me"/>

In javascript:

<script type="text/javascript">
    //button1 is the ID of asp:Button
    var objButton = document.getElementById('<%=button1.ClientID');
</script>
远山浅 2024-12-11 02:23:36

您可以像使用纯 html 按钮一样执行此操作。

<asp:Button id="foo" runat="server" />

变成

<input type="button" id="foo" />

如果您使用的是新版本的asp.net,您可以添加ClientIDMode =“Static”,这样id就不会更改为其他内容。

You do this like you would with a plain html button.

<asp:Button id="foo" runat="server" />

Turns into

<input type="button" id="foo" />

If youre using a new version of asp.net, you can add ClientIDMode="Static" so that the id doesnt change to something else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文