1

我正在尝试使用底层复选框构建一个简单的动画“开”和“关”开关控件,以便在“开关块”左右移动(开和关)时存储状态,当我将控件导入到页面时我需要使用,我得到的值总是 True,请指教我做错了什么。谢谢。:

澳交所:

<html>
<head>
    <title></title>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"> </script>
</head>
<body>

    <div class="switchcontainer">
        <div id="on">On</div>
        <div id="off">Off</div>
        <div class="block"></div>
    </div>
    <asp:CheckBox ID="chkSwitch" runat="server" Style="display:none"/>

            <script>
                $(".block").click(function () {
                    var $button = $(".block");
                    if ($button.data("lastMove") == "+=46") {
                        $('#<%= chkSwitch.ClientID %>').removeAttr('checked'); // --> change check state
                        $button.animate({
                            left: '-=46'
                        });
                        $button.data("lastMove", '-=46');
                    } else {
                        $('#<%= chkSwitch.ClientID %>').attr('checked', 'checked'); // --> change check state
                        $button.animate({
                            left: '+=46'
                        });
                        $button.data("lastMove", '+=46');
                    }
                });
</script>

</body>
</html>

ASCX.CS

public partial class BoolSwitch : System.Web.UI.UserControl
    {
        public bool On    
        {
            get { return chkSwitch.Checked; }
        }
    }

一些使用用户控件的页面:

<%@ Register TagPrefix="BoolSwitch" TagName="BoolSwitch" Src="/UserControls/BoolSwitch.ascx" %>

<BoolSwitch:BoolSwitch runat="server" ID="boolSwitch_1" />

代码背后:

        protected void Page_Load(object sender, EventArgs e)
        {
            var x = boolSwitch_1.On; // --> This value is always true;
        }
4

0 回答 0