php - 如何使用 php 通过 id 获取选择选项
问题描述
我想使用 php 通过 id 访问下拉菜单选项,就像我在 javascript 中所做的那样。我也想在 php 中完成这项工作。有没有办法做到这一点。请指导。我的 JS 代码是。
var opt = amove.options[amove.selectedIndex];
if(opt.id =="Exchange"){
document.getElementById('barcode2lb').style.display='block';
document.getElementById('barcode2txt').style.display='block';
}
else{
document.getElementById('barcode2lb').style.display='none';
document.getElementById('barcode2txt').style.display='none';
}
解决方案
例如,
<select>
<?php foreach($yourArr as $row):
if(yourConidtion){
$selected='selected';
}else{
$selected='';
}?>
<option value="<?= $row->id?>" <?= $selected ?>><?= $row->name ?></option>
<?php endforeach;?>
</select>
我想这就是你要求的
推荐阅读
- sql - 如何提高包含 Update 的 Merge 语句的性能
- apache-flink - 当 Flink 源算子为并行时,单个分区的输入顺序是否有保证?
- php - 未生成 PHP-FPM 核心转储
- flutter - 来自API的Flutter ListView分页?
- javascript - onClick 事件监听器在一段时间内
- c++ - 类模板继承的“尚未声明”错误
- java - 在 Java 中使用过滤器表达式的 DynamoDb 查询
- flutter - FutureBuilder 没有进入 builder?
- oracle - 指示行是否是使用 SQL 而不是 DAX 的实体 ID 值的第一个实例的新列
- prestashop - Prestashop 推荐链接