开发者

Option with 1 to 1000 [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 12 years ago.

开发者_如何学JAVA Improve this question

Can some one give me a html option tag thats goes from 1 to 100 ?


In PHP:

foreach (range(0,100) as $number)
 echo "<option value='$number'>$number</option>";


jquery:

for(var i = 1; i <= 100; i++)
{
  $(select).append("<option value='"+i+"'>"+i+"</option>"
}


In java:

for(int i = 1; i < 101; i++){
    System.out.println("<option value=" + i + ">" + i + "</option>");
}

Now you have 100 option tags from 1 to 100.


If you're doing it in PHP do you mean something like this:

echo '<select>
for($i = 1; $i < 101; $i++) {
  echo '<option value="'.$i.'">'.$i.'</option>';
}
echo '</select>';


Just use the HTML-element [option] combined with "label", like so:

<option label="1">Option one</option>
<option label="2">Option one</option>
[...]

The label allows for a value that's easy to proces automatically, and the text between the option-tags should be used to display something that's meaningful to the user.


in HTML5: <input type="range" min="1" max="100" /> or <input type="number" min="1" max="100" />


In javascript (I'm a bit rusty, untested):

select = document.getElementById('your-list'); 
for(i=0; i<=100; i++) {
    option = document.createElement('option');
    option.setAttribute('value', i);
    option.innerHTML = i;
    select.appendChild(option);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜