asp.net
  • jquery
  • 2010-04-23 41 views 1 likes 
    1

    我在窗体视图中有一个跨度。我想在加载时调用jQuery函数,我该怎么做?如何在窗体视图(asp.net控件)内调用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(“ModifiedO n“)%>','Countdown_ <%#Eval(”ProductID“)%>');”> 但不起作用

    +0

    你使用Firefox和萤火虫装BRO:

    更改您的跨线:

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

    ,并尝试这个jQuery(未测试)。第一件事,我会检查将语法或任何其他类型的错误.... – melaos 2010-04-23 09:39:56

    回答

    1

    我也许会尝试像这样的东西,而不是onload属性。我希望

    $(document).ready(function() { 
        $("span[id*=Countdown_]").each(function() { 
        var id = $(this).attr("id"); 
        var modified = $(this).attr("modified"); 
    
        GetTimeOnLoad(modified, id); 
        }); 
    }); 
    
    +0

    Thnaks Mikael它工作良好 – 2010-04-23 09:57:54

    0

    onLoad事件永远不会被span标记触发。你可以在$(document).ready()中触发你的方法的执行。

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

    我从FromView(asp.net控制)获取值并传递到该方法。因为数据来自服务器非常相同的数据我用作我的Jquery Funciton中的参数 – 2010-04-23 09:48:53

    相关问题