English 中文(简体)
采用j Query的新编号清单
原标题:Start new numbered list using jQuery
<ul>
    <li>test</li>
    <li>test</li>
    <li>test</li>
    <li>test</li>
    <li>test</li>
    <li>test</li>
    <li>test</li>
</ul>

<script>
$(document).ready(function(){   
    var increment=3;
    var start=8;
    $("ul").children().each(function(i) {
        $(this).prepend( <tag> +(start+i*increment).toString()+ .</tag> );
    });
});
</script>

Is there a way to start a new count for another ul list? With the code above this is what i get!

<ul>
<li> test
<li> test
<li> test
<ul/>

产出

1. test
2. test
3. test

第二编名单

<ul>
<li> test
<li> test
<li> test
<ul/>

产出:

4. test
5. test
6. test

而不是从第二个tag头开始1。 2. 仍在使用第一部第5条。 6. 结 论

So is it possible to reset the count and star it all over again for another ul tag? If it is possible how?

最佳回答

采用定购清单:

传真

<ol id="num_list">
  <li>How</li>
  <li>Now</li>
  <li>Brown</li>
  <li>Cow</li>
</ol>

CSS

#num_list { list-style-type: decimal; }

EDIT:如果你确实不能使用定购单,那么就使用一些 Java本,如:

$(function() {
  $( ul ).each(function() {
     $(this).children().prepend(function(index, html) {
        return  <span>  + (index+1) +  . </span> ;
     });
  });
});

rel=“nofollow”>jsFiddle example

问题回答
$( ul ).each(function() {
    $(this).children().each(function(i) {
        $(this).prepend( <span>  + (i + 1) +  .</span>  );
    });
});

http://jsfiddle.net/vSyK6/1/。

var increment = 1;
$( ul ).each(function() {
    var ul = $(this),
        li = ul.find( > li ),
        ol = $( <ol /> ).attr( start , increment);
    ul.after(ol);
    ol.append(li);
    ul.remove();
    increment += li.length;
});

例:

这样做时,将采用nes名单,因为它们(可能)看起来像这样:

1. One
2. Two
    4. Three
3. Four




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签