我正在尝试检索服务器端控件的offsetHeight,但它给了我一个错误。这是以下代码片段-

  function Test() {
            var imgFavorite = $("<%= imgFavorite.ClientID %>"); //imgFavorite is a server-side asp:Image control.
            alert(imgFavorite); //[object Object]
            alert(imgFavorite.offsetHeight()); //undefined.
   }


代码有什么问题?

最佳答案

使用ID声明jQuery对象时,您已经错过了哈希值:

var imgFavorite = $("#<%= imgFavorite.ClientID %>");

09-20 00:57