我在asp.net面板中创建了这个jQuery来启用/禁用子窗体元素,这个脚本将启用编辑窗体,但是在我第二次点击后有人可以帮我禁用它吗?
<script type="text/javascript">
$(function () {
//creating toggle
$("#check").button();
$("[id$='check']").data('isenabled', true); //enabled assumption
//disabled all input form
$("[id$=p_taskInfo]").children().prop("disabled", "disabled");
$("input[name='check']").click(function () {
var currentState = $(this).data('isenabled');
if (currentState) {
$("[id$=p_taskInfo]").children().removeProp("disabled");
}
else {
$("[id$=p_taskInfo]").children().prop("disabled", "disabled");
}
$(this).data('isenabled', !currentState);
}); //EOF click function
});//EOF function
</script>
答案 0 :(得分:0)
currentState 拼写错误,你需要在if ... else块中翻转两个语句,如下所示:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script src="Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("[id$=p_taskInfo]").children().prop("disabled", "disabled");
$("input[name='check']").click(function () {
var currentState = $(this).data('isenabled');
if (currentState) {
$("[id$=p_taskInfo]").children().prop("disabled", "disabled");
}
else {
$("[id$=p_taskInfo]").children().removeProp("disabled");
}
$(this).data('isenabled', !currentState);
});
});
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<input id="check" name="check" type="button" value="Enable\Disable" />
<asp:Panel ID="p_taskInfo" runat="server">
<asp:Button ID="Button2" runat="server" Text="Button" />
<asp:Button ID="Button3" runat="server" Text="Button" />
</asp:Panel>
</asp:Content>