代码之家  ›  专栏  ›  技术社区  ›  Basant B. Pandey

当jquery函数位于formview(asp.net控件)中时,如何调用它?

  •  1
  • Basant B. Pandey  · 技术社区  · 15 年前

    我在窗体视图的一侧有一个跨度。我想在from加载时调用jquery函数,我该怎么做?

    这是我的代码:

     <asp:FormView ID="FormView1" runat="server" OnItemCommand="FormView1_ItemCommand">
                <ItemTemplate>
                    <asp:HiddenField ID="hidProductID" Value='<%#Eval("ProductID") %>' runat="server" />
                    <asp:HiddenField ID="hidCustomerID" Value='<%#Eval("CustomerID") %>' runat="server" />
                    <a href='<%=WinToSave.SettingsConstants.SiteURL%>WintoSave/AuctionProduct.aspx?id=<%#Eval("ProductID") %>'>
                        <%#Eval("ProductName")%>
                    </a>
                    <br />
                    <img src='<%#Eval("ImagePath")%>' alt="Image No available" />
                    <br />
                    <asp:Label ID="lblTime" runat="server" Text='<%#Convert.ToDateTime(Eval("ModifiedOn")).ToString("hh:mm:ss") %>'></asp:Label>
    
                     <span id='Countdown_<%#Eval("ProductID") %>' onload="GetTimeOnLoad('<%#Eval("ModifiedOn")%>','Countdown_<%#Eval("ProductID") %>');"></span>
                    <br />
                    <asp:Label ID="lblFinalPrice" runat="server" Text='<%#Convert.ToDouble(Eval("FinalPrice")).ToString("#.00")%>'></asp:Label>
                    <br />
                    <asp:Label ID="lblFullName" runat="server" Text='<%#Eval("FullName") %>'></asp:Label>
                    <br />
                    <asp:Button ID="btnAddbid" Text="Bid" CommandName="AddBid" CommandArgument='<%#Eval("ID")%>'
                        runat="server" />
                </ItemTemplate>
            </asp:FormView>
    

    下面是我的jquery代码

       function GetTimeOnLoad(shortly,DivID)
       {
        var dt = new Date(shortly);
        alert(dt);
        alert(shortly);
        alert(DivID);
        var ProductDivID = "#" +DivID;
        alert(ProductDivID);
         $(ProductDivID).countdown({
                until: dt, onExpiry: liftOff, onTick: watchCountdown,
                format: 'HMS', layout: '{hnn}{sep}{mnn}{sep}{snn}'
            });
       }
       function liftOff(){};
       function watchCountdown(){};
    

    在上面的代码中 'onload=“gettimeonload('<%eval(“modifiedon”)%>','倒计时'uult;%eval(“productid”)%>');”> 但不起作用

    2 回复  |  直到 11 年前
        1
  •  1
  •   Mikael Svenson    15 年前

    我可能会尝试一些类似的东西,而不是onload属性。

    将跨距线更改为:

    <span id='Countdown_<%#Eval("ProductID") %>' modified='<%#Eval("ModifiedOn")%>' />
    

    并尝试此jquery(未测试):

    $(document).ready(function() {
      $("span[id*=Countdown_]").each( function() {
         var id = $(this).attr("id");
         var modified = $(this).attr("modified");
    
         GetTimeOnLoad(modified, id);
      });
    });
    
        2
  •  0
  •   mamoo    15 年前

    onload事件从不由SPAN标记触发。您可以在$(document.ready()中触发方法的执行;

      $(document).ready(function() {
          //put your call here...
      });