如何从 JavaScript 访问 ASPxTextBox 的值
假设我有一个 id 为“instrument”的 DevExpress ASPxTextBox。我想访问客户端文本框的值。所以我需要写一个javascript。
如果它是一个普通的 asp 文本框,我可以通过编写类似var InstrumentElement = document.getElementById('<%=instrument.ClientID%>')< 的代码来访问该文本框/code>
但是同样的方法不适用于 DevExpress 的文本框。
如何访问 ASPxTextBox ?我正在使用 Developer Express 7.2 版。
这是一些更彻底的代码片段 -
<div style="display: inline; float: left;">
<dxe:ASPxTextBox ID="InstrumentQuantity" runat="server" Width="170px">
</dxe:ASPxTextBox>
</div>
<div style="display: inline; float: left;" onclick="incOrDecQty(0);">
<asp:ImageButton ID="decrementQuantity" runat="server"
Height="16px" Width="16px" ImageUrl="~/images/left.png"
AlternateText="Decrease Quantity" PostBackUrl="javascript:void(0);"/>
</div>
<div onclick="incOrDecQty(1);">
<asp:ImageButton ID="incrementQuantity" runat="server"
AlternateText="Increase Quantity" ImageUrl="~/images/right.png"
Height="16px" Width="16px" PostBackUrl="javascript:void(0);" />
</div>
那是 ASP 代码。对应的Javascript如下:
function incOrDecQty()
{
var element = document.getElementById('<%=InstrumentQuantity.ClientID%>');
var lotSize = parseInt(document.getElementById('<%=LotSize.ClientID%>')
.innerHTML, 10);
var currentValue = parseInt(element.value,10);
if(arguments[0] == 1)
currentValue += lotSize;
else if((currentValue - lotSize) >= 0 )
currentValue -= lotSize;
element.value= currentValue;
}
Suppose I have an DevExpress ASPxTextBox whose id is "instrument". I want to access the value of the text box at client side. So I need to write a javascript.
If it was a normal asp text box, I could have accessed the text box by writing code like
var instrumentElement = document.getElementById('<%=instrument.ClientID%>')
But the same approach is not working for the DevExpress's Text Box.
How can I access an ASPxTextBox ? I am using Developer Express Version 7.2.
Here is some more thorough code snippet -
<div style="display: inline; float: left;">
<dxe:ASPxTextBox ID="InstrumentQuantity" runat="server" Width="170px">
</dxe:ASPxTextBox>
</div>
<div style="display: inline; float: left;" onclick="incOrDecQty(0);">
<asp:ImageButton ID="decrementQuantity" runat="server"
Height="16px" Width="16px" ImageUrl="~/images/left.png"
AlternateText="Decrease Quantity" PostBackUrl="javascript:void(0);"/>
</div>
<div onclick="incOrDecQty(1);">
<asp:ImageButton ID="incrementQuantity" runat="server"
AlternateText="Increase Quantity" ImageUrl="~/images/right.png"
Height="16px" Width="16px" PostBackUrl="javascript:void(0);" />
</div>
That was the ASP Code. The corresponding Javascript is as follows :
function incOrDecQty()
{
var element = document.getElementById('<%=InstrumentQuantity.ClientID%>');
var lotSize = parseInt(document.getElementById('<%=LotSize.ClientID%>')
.innerHTML, 10);
var currentValue = parseInt(element.value,10);
if(arguments[0] == 1)
currentValue += lotSize;
else if((currentValue - lotSize) >= 0 )
currentValue -= lotSize;
element.value= currentValue;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在 AspxTextBox 上设置 ClientInstanceName 属性。
客户端:
devexpress 文档在其客户端脚本上提供了一些非常好的信息。转到此链接,单击“参考”,然后单击“DevExpress.Web.ASPxEditors”。菜单上的脚本。
You can set the ClientInstanceName property on the AspxTextBox.
ClientSide:
The devexpress documentation has some pretty good info on their client side scripts. Go to this link, click on Reference, then click on DevExpress.Web.ASPxEditors.Scripts on the menu.
以下是 ASPxTextBox 上的所有客户端方法和事件。
http://www.devexpress.com/Help/?document=ASPxEditors/ DevExpressWebASPxEditorsScriptsASPxClientTextBox_ctortopic.htm
Here are all the Client Side methods and events on the ASPxTextBox.
http://www.devexpress.com/Help/?document=ASPxEditors/DevExpressWebASPxEditorsScriptsASPxClientTextBox_ctortopic.htm
第三方文本框可能未使用 ClientID。您可以尝试 UniqueID,尽管这可能不是全局可接受的修复(可能不适用于所有浏览器)。
It's possible that the third party textbox does not make use of the ClientID. You might try UniqueID, though this may not be a globally acceptable fix (might not work in all browsers).
这种获取客户端 DevExpress ASPxClientTextBox 的方法对我有用:
基于以下解决方案: https://stackoverflow.com/a/44251251/
This method of getting the client-side DevExpress ASPxClientTextBox worked for me:
Based on solution from: https://stackoverflow.com/a/44251251/