$('#<%=nameLabel.ClientID%>') does not work when in .js file and works when in script is in the page

后端 未结 5 1385
再見小時候
再見小時候 2021-01-28 19:08

$(\'#<%=nameLabel.ClientID%>\') is being used in my script for jquery.

When this is in ... block in tha page , it works fine ,as its a content page i

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-28 19:38

    Like the others have explained <%=nameLabel.ClientID%> needs to run on the server. You could however do something like this:

    $("[id$=_nameLabel]")
    

    Checks all ids and matches those that end with _nameLabel.

提交回复
热议问题