0

I created this jQuery to Enable/Disable child Form Elements inside the asp.net panel this script will enable edit form but it will not Disable it after i click for second time can someone help me ?

 <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>
4

1 に答える 1

0

currentStateのスペルが間違っているため、次のように、if...elseブロックの2つのステートメントを入れ替える必要があります。

 <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>
于 2013-01-02T19:59:06.007 に答える