我的问题是我不知道如何捕获从组合框列表中选择的数据,我的意思不是值 1、2、3、4,我的意思是组合显示的内容,在我的情况下,团队名称,我带来用js的数据,它会插入我从列表中选择的数值,这很好,但我还需要获取并插入团队名称,而不仅仅是值。
从这里我提取数据,按部门 ID 过滤。
$query = $conexion->query("SELECT * FROM equipos WHERE idDepto = $depto");
echo '<option value="0">Seleccione</option>';
while ($row = $query->fetch_assoc()) {
echo '<option value="' . $row['idEquipo'] . '">' . $row['Nombre'] .
'</option>' . "\n";
}
通过这个 Js 函数,我将它们传递给 HTML,在 HTML 中我只使用“cmbequipos”。
$(function(){
// Lista de Deptos
$.post( 'departamentos.php' ).done( function(respuesta)
{
$( '#cmbdeptos' ).html( respuesta );
});
// lista de Deptos
$('#cmbdeptos').change(function()
{
var el_continente = $(this).val();
// Lista de Eqs
$.post( 'equipos.php', { continente: el_continente} ).done( function( respuesta )
{
$( '#cmbequipos' ).html( respuesta );
});
});
// Lista de Equipos
$( '#cmbequipos' ).change( function()
{
var pais = $(this).children('option:selected').html();
});
})
HTML 视图
<select name="cmbequipos" class="form-control input-sm" required="Yes"
id="cmbequipos" <?php echo $_SESSION["status"]; ?>>
</select>
在插入的那一刻,我放了这样的东西,$var = $_POST['cmbequipos'];
但在这种情况下它插入了 Team id 的值。但我尝试使用名称而不是值。
我设法解决了它,因为我只插入了 id 值,所以我决定在插入的那一刻我会进行查询并给我带来设备的名称,因为我只插入了 id,这样的东西仍然存在。
尝试这个