asp.net mvc - JQuery - How to get at all the data -
I have a paging menu partial view in my MVC app that looks like:
& Lt; % If (model total page & gt; 5) {int index = Model.PageIndex; Int minIndex = Index - 2; Int maxIndex = Index + 2; If (index & lt; 2) {minIndex = 0; Max Index = 4; } If (index> model total page - 2) {minIndex = model total page - 5; MaxIndex = model total page; } For (int i = min indices; i = MAX index; i ++) {%> & Lt; Li & gt; & Lt; Span class = "& lt;% = Html.GetClass ((i == index)," selected "," non-selected ")% & gt;" & Gt; & Lt; A href = " "class =" & lt;% = Html.GetClass ((i == index), "selected", "non-selected")% & gt; " & Gt; & Lt;% = i + 1% & gt; & Lt; / A & gt; & Lt; / Span & gt; & Lt; / Li & gt; & Lt;%}} and {for (Inti = 0; I> Model Total Page; i ++) {%> & Lt; Li & gt; & Lt; Span class = "& lt;% = Html.GetClass ((i == model page index)," selected "," non-selected ")% & gt;" & Gt; & Lt; A href = " & gt; & gt; & Lt;% = i + 1% & gt; & Lt; / A & gt; & Lt; / Span & gt; & Lt; / Li & gt; & Lt;%}}% & gt;
I did not know how to set up a JQuery click event on anchor tag. Anchor tag does not have a NAME feature and my (very limited) experience with JQuery is that it needs to work with NAME features
< / P>
Specify any CSS selector to get you on your tags And not only a name / id For example, if you want all anchor tags in your document to subscribe to your event, such as
$ ("a"). Click (function () () * {magic * *}); will work, it disturbs every other anchor tag on the page, which can not have any effect for you.
If you want to give your tag a general behavior, sometimes it's a custom CSS class so that you can hook up events through another simple selector
$ (".pager link"). Click (function () {/ * magic *}}; If you think an alternative UL tag is to give an ID, then it does not like to think, then use a descendant selector
$ ("#yourPager One"). Click (function ()) {/ * Magic *}}; Or looking at your markup, a child selector can also be possible
$ ("span.selected> gt; a, span.notselected & gt; ; A "). Click (function ()) {/ * spell *}); i.e. Search for all tags, which are the immediate descendants of Span tags, which do not have a selected class or selected class.
It is appropriate to remember that you have to cancel the default behavior of the tag (such as your navigational link), either by giving false to your event handler or preventing default