- <?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>
- //该片段来自于http://www.codesnippet.cn/detail/171020136460.html
来源: http://www.codesnippet.cn/detail/171020136460.html