开发者

adding an ID Number to a CSS Tag

I am inspecting the html at this site: listverse.com

I see that they have inserted ID numbers in the List Tags开发者_运维百科 such as

 <li id="comment-220669">

What is the comment-220669 for. And what are they using it for?

If they are using this ID tag to pass information back to the server. How can i do this using c# asp.net mvc?


I´m pretty sure it´s an inpage link target so you can point out the comment e.g. http://listverse.com/2009/11/12/top-10-tips-for-urban-exploration/#comment-224593


They are most likely generating those to uniquely identify each comment when they view source as it's not very likely or practical to apply styles this way. They are probably accomplishing this (assuming MVC) by looping through a collection of comments and attaching the CommentID to the id field like so:

<% foreach(var comment  in Model) { %>
    <li id="comment-<%= comment.CommentID  %>">Foo</li>
<% } %>

I highly doubt they are using this to pass any information back to the server (Never tried but I think you could do it by parsing the id attribute with jQuery).

If you need to work with the CommentID for a scenario like this you're better of adding it to a query string that goes to an action method, or populating a hidden field in a form that posts to an action method.


I think they i have been assign Id on every comment of user, and system used that comment id for any function by ajax call when user press mouse over it, click over that list tag etc...

so at every click event system can find the unique reference


Looks like a wordpress blog - with wordpress they use an 'almost' microformat to display posts I think the way the comments are markedup relates to this. As other people say the id provides a way of targetting a particular element using javascript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜