ASP.Net Ajax $find() Jquery Equivalent

前端 未结 5 1892
名媛妹妹
名媛妹妹 2020-12-19 00:33

Is there a JQuery equivalent of ASP.Net Ajax\'s $find() function?

$() != $find()
5条回答
  •  感动是毒
    2020-12-19 01:12

    If you want to find an element by its ASP.NET code ID rather than the generated ClientID (ctl00_RealId) then you can use this function. It just looks for elements that have an ID that ends with _{the real ID here}:

    var $$ = function (id, context) {
        var $ = (jQuery) ? jQuery : return ;
        var el = $("#" + id, context);
          if (el.length < 1)
            el = $("[id$=_" + id + "]", context);
        return el;
    }
    

    For example, say your ID in your code is pnlSuccess, say a panel:

    
    

    But in the rendered code it comes out as: ctl00_content_ctl00_pnlSuccess

    calling $$("pnlSuccess") will find that rendered panel.

提交回复
热议问题