English 中文(简体)
按相对位划分项目。 例5
原标题:Counting and grouping items by relative position. grouping by 5 s for instance

想法是,将有一个与目录中每个图像的html相呼应的实验室功能。

我的数字是,每个(有些情况一样)都走过这个阵列,把价值观分配到 im的价值观中。

但是,为了发挥职能,分配能够达到的等级价值。

我需要能够根据规定而不是人工的定位安排班级。

一组物体的相对位置。 例如,在目录中,有50个图像显示,这些文档中有许多功能为每个项目分配类别(一个功能在变数中完成,即怀疑)生成成像标记,通过5个类别,产出与产出一样。

<img class="a" src="example">
<img class="b" src="example">
<img class="c" src="example">
<img class="d" src="example">
<img class="e" src="example">

<img class="a" src="example">
<img class="b" src="example">
<img class="c" src="example">
<img class="d" src="example">
<img class="e" src="example">


<img class="a" src="example">
<img class="b" src="example">
<img class="c" src="example">
<img class="d" src="example">
<img class="e" src="example">


<img class="a" src="example">
<img class="b" src="example">
<img class="c" src="example">
<img class="d" src="example">
<img class="e" src="example">


<img class="a" src="example">
<img class="b" src="example">
<img class="c" src="example">
<img class="d" src="example">
<img class="e" src="example">


<img class="a" src="example">
<img class="b" src="example">
<img class="c" src="example">
<img class="d" src="example">
<img class="e" src="example">

现在,第50和50号;第5号是假设的,我更有可能使用7或12个班级分配周期。

确实,请我如何这样做? 我只读过我自己的东西,这确实很重要。

最佳回答
$cycle = 5;    
$classes = array(  a ,  b ,  c ,  d ,  e ,  f ,  g ,  h  );
$i = 0;
foreach( $files as $file ) {
    echo  <img class=" .$classes[ $i % $cycle ]. " src=" .$file. "> ;
    ++$i;
}
问题回答

你基本上寻找模块操作者。 我认为,它也以javascript语提供,下面是两个地方使用的购买力平价例子。

  1. To cycle through an array of available class names.
  2. To insert a line-break after each X images.

rel=“nofollow”>modulo营运人%<<<>Docs/em><> > 退还一个司业务的剩余价值。

rel=“nofollow> Demo:

$images = array_fill(0, 50,  example ); // 50 example images
$classes = range( a ,  e ); // 5 example classes (a-e)

foreach($images as $index => $src)
{
    # get image class    
    $class = $classes[$index % count($classes)];

    printf( <img class="%s" src="%s"> ."
", $class, $src);

    # echo empty line after each 5th image
    if (4 === $index % 5)
        echo "
";
}

产出:

<img class="a" src="example">
<img class="b" src="example">
<img class="c" src="example">
<img class="d" src="example">
<img class="e" src="example">

<img class="a" src="example">
<img class="b" src="example">
<img class="c" src="example">
<img class="d" src="example">
<img class="e" src="example">

<img class="a" src="example">
<img class="b" src="example">
...




相关问题
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.

热门标签