JS or jQuery method for obtaining the ASP. NET Server Control ID, jqueryasp.net
In ASP. when js is used in. NET, JavaScript often cannot obtain DOM elements because of incorrect methods. Now we will introduce a method to solve the problem of getting ASP using js.. NET controls generate the id corresponding to the html tag on the browser side
1. Obtain the id of the tag generated by the server control on the browser, that is, the client html Tag id of the server control.
The ClientID attribute of the server control can be used to obtain the corresponding id value in the browser, that is, the html tag of the client. The method is as follows:
The Code is as follows:
Copy codeThe Code is as follows:
<% = NewsId. ClientID %>
2. Get the corresponding dom Element Through dom
It can be obtained through js or document or jquery. Here we use jquery as an example.
The Code is as follows:
Copy codeThe Code is as follows:
Var newsId =$ ("# <% = newsId. ClientID %> ");
3. Operate dom elements
Now that you have obtained the elements to be operated, you can perform the corresponding operations. Then you can start to "do whatever you want ~~~