【问题标题】:Way to delay/timeout postback in jQuery?在jQuery中延迟/超时回发的方法?
【发布时间】:2015-09-13 07:36:12
【问题描述】:

有没有办法延迟/超时从 jQuery 中的 listview 按钮回发?我想在回发之前制作淡出动画,当点击按钮时触发。有什么想法吗?

我的代码:

$(document).ready(function () {
    $('.btndown').click(function () {
        $('.imageset').animate({ 'opacity': 0 }, 1000);
    });
});

按钮标记,当它被点击时得到回发:

<div class="btndown">
      <asp:DataPager ID="DataPager2" runat="server" PagedControlID="Listview1" PageSize="3">
            <Fields>
                <asp:NextPreviousPagerField ButtonType="Image" FirstPageText="" LastPageText="" NextPageImageUrl="~/images/arrowbtndown.png" NextPageText="" PreviousPageText="" ShowPreviousPageButton="False"/>
            </Fields>
      </asp:DataPager>
</div>

按钮输出:

<input type="image" name="ctl00$ContentPlaceHolder1$DataPager2$ctl00$ctl00" src="images/arrowbtndown.png">

【问题讨论】:

  • 您的回发是什么样的?也提供。
  • 回发正在更改列表视图中的页面。我想在回发之前将它淡出,因为在 pageLoad 上我有淡入,所以它会是一个平滑的淡出/淡入效果。
  • @Ashiv3r:发布您的按钮标记,n 何时回发?

标签: jquery asp.net postback


【解决方案1】:

不要使用超时,使用animation complete callback

// This stops the `postback` from being fired on the `<asp>` generated button.
$('.btndown input').click(function(e){
    e.preventDefault();
});

$('.btndown').click(function (e) {
    e.preventDefault();
    $('.imageset').animate({
       'opacity': 0
    }, 1000, function() {
          // Animation has completed
          // Trigger the 'postback' JS function, whatever this may be.
    });
});

取决于输出的内容:

<asp:DataPager ID="DataPager2" runat="server" PagedControlID="Listview1" PageSize="3">
        <Fields>
           <asp:NextPreviousPagerField ButtonType="Image" FirstPageText="" LastPageText="" NextPageImageUrl="~/images/arrowbtndown.png" NextPageText="" PreviousPageText="" ShowPreviousPageButton="False"/>
        </Fields>
 </asp:DataPager>

会有所不同,因为此输出可能会在点击时立即触发回发。如果您分享最终输出,它可能会有所帮助。

【讨论】:

  • 最终输出:。不幸的是,你的 jQuery 也不起作用。
  • 我的代码sn-p只是动画部分,需要在我提到的动画完成回调中手动禁用&lt;input/&gt;,然后手动触发postback函数。我不知道&lt;asp&gt; 按钮绑定了哪些javascript 事件。您需要了解更多关于该按钮对 JS 的作用。你可以通过$('.btndown input').click(function(e){e.preventDefault()});来阻止它触发。
  • 我需要回发我的 .btndown 名称属性,但我不知道如何在 __doPostBack(); 中执行此操作
【解决方案2】:

编辑

最终解决方案如下:

<script type="text/javascript">
function pageLoad() {

    $('.btndown').click(function (e) {
        e.preventDefault();
        $('.imageset').animate({
          opacity: 0
          }, 1000, function () {
                 __doPostBack($('.btndown input').attr('name'), '');
          });
    });
};
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    • 2014-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多