如何在asp:CustomValidator javascript函数中获取父级
How can I get the parent in the asp:CustomValidator javascript function
如何在asp:CustomValidator javascript函数中获取父项,以便使用它来检查相关复选框是否已选中?
示例:
我有以下代码:
<tr>
<th class="graytext r">Add Reps to Team:</th>
<td>
<asp:GridView ID="grid" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID"
DataSourceID="dsEmployees" EnableViewState="false"
GridLines="None" CssClass="clGridDirectory">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox runat="server" ID="employee_name" CssClass="employee_name" Text='<%# Eval("fullname") %>'/>
<asp:HiddenField runat="server" ID="employeeidToRep" Value='<%# Eval("employeeid") %>'/>
<asp:TextBox runat="server" ID="repID" Text='<%# Eval("rep_id") %>' />
<asp:CustomValidator id="CustomValidator2" runat="server"
ControlToValidate = "repID"
ErrorMessage = ""
ClientValidationFunction="test" >
</asp:CustomValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsEmployees" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="app_staff_without_team_select" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
</td>
</tr>
Jquery代码:
function test(oSrc, args) {
var $tb = $('input[id$=employee_name]');
// only validate if an <asp:Checkbox> called chkOtherCheckbox is ticked
alert(args.Value.toString())
if ($('input:checkbox[id$=chkOtherCheckbox]').is(':checked'))
alert('checked')
else
alert('no checked')
}
如何在测试函数中获取父项,以便使用它检查相关复选框是否已选中?
您可以使用此代码来获取最近复选框的状态。
function test(oSrc, args) {
var nearestCheckBox= $(oSrc).parent().find('input:checkbox:first');
var state=nearestCheckBox.attr('checked');//use this variable
}
相关文章:
- 使用jQuery来foreach iframe-src,并通过函数获取ID和操作
- Javascript函数获取元素内容
- 从Javascript函数获取字符串
- Jasmine测试工厂函数调用本地函数和另一个函数-获取错误:应该是间谍,但得到了function
- 从 JavaScript 函数获取 NaN 尝试多次获取相同的数据
- 从 JS 函数获取 PHP 中的值
- 如何用一个函数获取所有javascript变量
- Javascript-函数获取数组元素参数未定义/为null
- 从回调函数获取xhr状态
- 有没有一种方法可以让watch函数获取被监视文件的名称
- 从JQuery到Javascript函数获取表单对象
- 使用react.js从api函数获取json数据
- 从javascript中的递归函数获取undefined
- 使用sails.js中的beforeConnect函数获取客户端套接字
- 如何通过类名和过滤函数获取属性值
- 从php函数获取值到javascript
- 从外部函数获取参数名称
- 从方法js中的函数获取对象属性
- 使用Jquery.load()函数获取变量和页面片段
- 使用onclick函数获取点击的元素jquery