当前位置: 动力学知识库 > 问答 > 编程问答 >

datepicker doesn't show in asp.net using javascript, jquery

问题描述:

I'm having a problem sliding Up and down the jquery datepicker on a click of a linked button. When the button is clicked, the text of the button is changed and depending on the text of the button datepicker is shown or hidden. Nothing is happening, only the name of the link button is changed quickly and changed back right away.

And the other question: if on document.ready I don't hide datepicker, it shows and disappears when some other trigger on the page is clicked. Why does it happen?

Here is what I have now:

<script>

$(document).ready(function() {

$($('#datepicker').datepicker({

minDate: new Date('04/26/1985'),

maxDate: "-1Y",

dateFormat: "yy-mm-dd"

})).hide();

});

function clicked() {

if ($('#<%=link_btn.ClientID%>').text() == "Later dates") {

$('#<%=link_btn.ClientID%>').text("Older dates");

$('#datepicker').slideUp();

return false;

}

if ($('#<%=link_btn.ClientID%>').text() == "Older dates") {

$('#<%=link_btn.ClientID%>').text("Later dates");

$('#datepicker').slideDown();

return false;

}

}

网友答案:

Hiding the datepicker in this way will always hide the datepicker. I would do in this way:

In the markup:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script>
        $(document).ready(function () {
            $($('#datepicker').datepicker({
                minDate: new Date('04/26/1985'),
                maxDate: "-1Y",
                dateFormat: "yy-mm-dd"
            }))
        });
        function ToggleDate(myvalue) {
            if (myvalue == "Later dates") {
                $('#datepicker').show().slideUp();
            }
            else {
                $('#datepicker').slideDown();
            }

        };

    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input id="datepicker" type="text" />
            <asp:LinkButton ID="link_btn" runat="server" OnClick="link_btn_Click">Later dates</asp:LinkButton>
        </div>
    </form>
</body>
</html>

And in the code:

protected void link_btn_Click(object sender, EventArgs e)
{
    string myScript = "ToggleDate('" + link_btn.Text + "');";
    Page.ClientScript.RegisterStartupScript(this.GetType(), "RegisterStartupScript", myScript, true);
    link_btn.Text = link_btn.Text == "Later dates" ? "Older dates" : "Later dates";
}

Hope it helps!

分享给朋友:
您可能感兴趣的文章:
随机阅读: