本文实例讲述了php使用数组填充下拉列表框的方法。分享给大家供大家参考。具体实现方法如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<?php $data = array ( (object) array ( "titulo" => "Ford" , "valor" => "opcion1" ), (object) array ( "titulo" => "Peugeot" , "valor" => "opcion2" ), (object) array ( "titulo" => "Chevrolet" , "valor" => "opcion3" ), (object) array ( "titulo" => "Volskwagen" , "valor" => "opcion4" ), ); ?> <html> <header> <script> function onCambioDeOpcion(combobox) { alert( "Seleccionaste: " + combobox[combobox.selectedIndex].text + " \nSu valor es: " + combobox.value); } </script> </header> <body> <select class = "select_autor" name= "autor" onchange= "onCambioDeOpcion(this)" > <option selected= "selected" >Seleccione fabricante</option> <?php for ( $i =0; $i < count ( $data ); $i ++) { ?> <option value= "<?php echo $data[$i]->valor ?>" > <?php echo $data [ $i ]->titulo ?></option> <?php } ?> </select> </body> </html> |
希望本文所述对大家的php程序设计有所帮助。