开发者

Get value of nth item in an un-ordered list

For this code,

<ul id="date-list" hidden="hidden">
<% foreach (string item in (List<string>)Model.OpenCloseTime)
   {%>
    <li value="<%= item %>"><%= item %></li>
<% }%>
</ul>

How could i get the value of nth item in the list. It is an MVC project and we are using jquery. 开发者_如何学编程 Basically I am trying to use the string value as a min max time for an input of type="time".

Thanks!


var found = $('#date-list').find('li').eq(n).text()


$('#date-list').children().eq(n).attr('value');

However, if you want a custom data attribute, html5 states you should precede it with data-

<li data-value="<%= item %>"><%= item %></li>

$('#date-list').children().eq(n).data('value');


Here you go:

$( '#date-list' ).children().eq( n ).text()


$('#date-list>li:nth-child('+n+')'.attr('value');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜