我想像我在javascript中一样使用php通过id访问下拉列表选项。我也想在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';
}
答案 0 :(得分:0)
如果您使用原始php,则
<select name="">
<option value=""> select a option </option>
<?php
$sql = 'SELECT * FROM table ORDER BY id ASC';
$result_select = mysql_query($sql);
$rows = array();
while($row = mysql_fetch_array($result_select)){
if($row['which column you want to compare'] == value){
echo "<option value="".$row['value index']."">".$row['value index']." </option>"
}
}
?>
答案 1 :(得分:0)
例如,
<select>
<?php foreach($yourArr as $row):
if(yourConidtion){
$selected='selected';
}else{
$selected='';
}?>
<option value="<?= $row->id?>" <?= $selected ?>><?= $row->name ?></option>
<?php endforeach;?>
</select>
我想这就是你要的
答案 2 :(得分:0)
class App extends React.Component {
state = {
data_rows: [
[
"Research",
"Find sources",
new Date(2015, 0, 1),
new Date(2015, 0, 5),
null,
100,
null
],
[
"Write",
"Write paper",
null,
new Date(2015, 0, 9),
daysToMilliseconds(3),
25,
"Research,Outline"
],
[
"Cite",
"Create bibliography",
null,
new Date(2015, 0, 7),
daysToMilliseconds(1),
20,
"Research"
],
[
"Complete",
"Hand in paper",
null,
new Date(2015, 0, 10),
daysToMilliseconds(1),
0,
"Cite,Write"
],
[
"Outline",
"Outline paper",
null,
new Date(2015, 0, 6),
daysToMilliseconds(1),
100,
"Research"
]
]
};
onAddRow() {
let newState = Object.assign({}, this.state);
newState.data_rows.push([
"Task" + newState.data_rows.length,
"Some new task",
null,
new Date(2015, 0, 6),
daysToMilliseconds(1),
100,
"Research"
]);
this.data_rows++;
this.setState(newState);
}
getHeight() {
if (document.getElementsByTagName("svg")[0]) {
document
.getElementsByTagName("svg")[0]
.setAttribute("height", (this.state.data_rows.length + 1) * 42);
document
.getElementsByTagName("svg")[1]
.setAttribute("height", (this.state.data_rows.length + 1) * 42);
}
return (this.state.data_rows.length + 1) * 42;
}
render() {
return (
<div className="App">
<span
style={{ backgroundColor: "#0f0", cursor: "pointer" }}
onClick={() => this.onAddRow()}
>
add row
</span>
<div id="chart_div">
<Chart
chartType="Gantt"
data={[columns, ...this.state.data_rows]}
width="100%"
height={this.getHeight()}
legendToggle
/>
</div>
<div>
</div>
</div>
);
}
}
是服务器端语言,因此您将需要PHP
使用AJAX发布ID值。从您的JS
代码进行AJAX调用,并处理JS
代码中的数据