簡體   English   中英

從代碼后面動態調用jQuery

[英]dynamically calling jquery from code behind

好的,所以我試圖生成N個div,並將它們添加到標記中,然后從Jquery lib中對其調用“可拖動”功能。 我已經在頁面上完成了div的添加,現在我只需要調用函數,這就是我遇到的麻煩。 這是我到目前為止的內容:

    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFoo", "<script type='text/javascript'>myFunction($('#draggable2').draggable());</script>", false);

更新:我已經解決了。 它雖然不漂亮,但是可以用,任何建議都很棒!

public static class MyExtensions
{
    public static void DragAble(this HtmlGenericControl NewDiv)
    {
        NewDiv.Attributes["class"] = "ui-widget-content";
        string dragmenow = "<script>$(function () { $(\"#" + NewDiv.ClientID + "\").draggable(); });</script>";
        NewDiv.Controls.Add(new Literal() { Text = dragmenow });
    }
}   

謝謝!

試試這個代碼:

刪除了腳本塊,並添加了文檔就緒。

  Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFoo", "$(function (){myFunction($('#draggable2').draggable());});", true);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM