gpt4 book ai didi

asp.net - JavaScript - ASP.net - 循环访问 asp 面板上的所有控件

转载 作者:行者123 更新时间:2023-12-02 20:45:41 24 4
gpt4 key购买 nike

我是否也可以循环遍历 asp.net 面板上的所有控件,并检查每个控件的类型以查看其是否为 asp 类型 TimeInput?

JS 基本上需要复制此服务器端 VB.net 代码

 'this is checking that something has been entered into at least one of the time input boxes
Protected Sub valCusAllTextBox_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles valCusAllTextBox.ServerValidate
'When the Save or Submit button is clicked the Page.IsValid() command causes the "valCusAllTextBox" custom validator control
'(which was dragged on to the page) to call this event - where we do our customised error checking
args.IsValid = False 'args.IsValid is a system function
'check all controls within the Overtime Claim panel
For Each ctrl As Control In pnlOvertimeClaim.Controls
If TypeOf ctrl Is TimeInput Then
If CType(ctrl, TimeInput).TimeInMinutes <> 0 Then
args.IsValid = True
Exit For
End If
End If
Next
If txtOnCallAllow.Text.Trim() <> "" Then
args.IsValid = True
End If
If txtMealAllow.Text.Trim() <> "" Then
args.IsValid = True
End If
End Sub

最佳答案

您可以使用此脚本从面板中查找特定控件,将脚本放在页面末尾,

<script type="text/javascript" language="javascript">
var pnl = document.getElementById('pnl')
var array = pnl.getElementsByTagName("a");
for (var n = 0; n < array.length; ++n) {
alert("anchor");
}
var array = pnl.getElementsByTagName("img");
for (var n = 0; n < array.length; ++n) {
alert("Image");
}

就像这是您的面板,您想要迭代特定的控件。

<asp:Panel runat="server" ID="pnl">
<a id="sd" href=""></a>
<img src="" />
<a id="A1" href=""></a>
</asp:Panel>

关于asp.net - JavaScript - ASP.net - 循环访问 asp 面板上的所有控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1265382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com