ASP.NET中的JQUERY .show()函数 [英] JQUERY .show() function in ASP.NET

查看:54
本文介绍了ASP.NET中的JQUERY .show()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JQuery 1.5.2.

I'm using JQuery 1.5.2.

虽然使用.show函数,但它仅部分显示元素(如0.3秒),然后元素再次隐藏自身.这与所有其他形式是一致的.我在做什么错了?

Whilst using the .show function, it only shows the element partly, for like 0.3 seconds, and then the element hides itself again. This is consistent, with all other forms. What am I doing wrong?

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.5.2.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function () {

        $('#Button1').click(function () {
            $('#clickmeupdate').show(function () {

            });
        });

    });
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
    <span style="background-color:Blue; display: none" id="clickmeupdate" >Click me to update</span>
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

推荐答案

该按钮正在回发,并且在显示时设置为无.

The button is posting back and when it does the display is set back to none.

您可以通过不使用asp.net按钮,仅使用html按钮或添加onClick事件并返回false来停止回发.

You can stop the postback by not using an asp.net button, just use an html button or by adding an onClick event and return false.

编辑- 我已经调整了答案,因为在您提到的评论中您需要按钮单击事件.

EDIT - I've adjusted my answer since in the comments you mentioned you needed the button click event.

您仍然可以通过使用OnClientClick来运行jQuery来执行此操作. 查看此以获得更多信息.

You can still do this by using the OnClientClick instead to run the jQuery. See this for more info.

但是,由于先发生OnClientClick,然后再发生onClick,因此仍然存在回发将跨度重置为不显示的问题.

However, you still have the issue of the postback resetting the span to not display since the OnClientClick occurs first and then the onClick.

我认为您真的想为此设置一种AJAX解决方案,或者只是将span设置为runat = server,然后在按钮后面的代码中将其设置为可见.

I think you really want to setup an AJAX kind of solution for this OR just have your span be set to runat=server and in your code behind of the button click set it to visible.

我怀疑,虽然您最好选择 jQuery AJAX解决方案完成所有这些操作,但可能方便您使用Web窗体UpdatePanel.

I suspect though you would be better served to check out the UpdatePanel / AJAX stuff in Asp.Net web forms. You could do all this with jQuery AJAX solution but it may be easier for you to use the web forms UpdatePanel.

这篇关于ASP.NET中的JQUERY .show()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆