What is the different within jQuery('[id$="myID"]') and $("#<%=myID.ClientID %>")?
What is the different within jQuery('[id$="my开发者_StackOverflow中文版ID"]') and $("#<%=myID.ClientID %>") ? Which one should be the standard?
jQuery('[id$="myID"]')
- this selects an element which id is ending with myID
$("#<%=myID.ClientID %>")
- this selects an element with id == myID.ClientID
As for me I'd prefer the second one, it guarantees that exactly 1 element with the specified id will be selected. If you are sure that you have only one element with id ending with myID
you can use any of them.
Attribute Ends With Selector [name$="value"]
Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.
ID Selector (“#id”)
Selects a single element with the given id attribute.
I suppose the second one should be a better choice.
I guess you may using jqote templating plugin.
The first one jQuery('[id$="myID"]')
is jquery endsWith selector.
Second one $("#<%=myID.ClientID %>")
is just an ID selector. But you may be using $("#<%=myID.ClientID %>")
in a different place than a typical javascript file. I used to have <%=....%>
in jqote templating plugin, to embed javascript inside a html template.
精彩评论