gpt4 book ai didi

javascript - POST 后选择 ="selected"?

转载 作者:行者123 更新时间:2023-11-29 12:14:21 27 4
gpt4 key购买 nike

我只想在将代码发送到 Iframe 后保持列表框项目的选中状态,但我真的不知道该怎么做...这是我的代码 ^^

<?PHP
if(isset($_POST['options'])){
$epinum = $_POST['options'];
}
?>
<form action="" method="post">
<SELECT class='listofepisodes' NAME='options' onchange='this.form.submit()' size='1200'>
<?PHP
$options=mysql_query("SELECT * FROM table");
while($option=mysql_fetch_array($options)) {
$image=$option['link'];
$number=$option['number'];
?>
<option value="<?PHP echo $image; ?>">Option <?PHP echo $number; ?></option>
<?PHP } ?>
</SELECT>
</form>
<iframe name="iframe" src="<?PHP echo $epinum; ?>" height="388" width="640" frameborder="1" allowfullscreen></iframe>

最佳答案

只需将 $_POST['options'] 与 $image 进行比较,然后将“selected”回显到选项标记,如下所示:

<?PHP
if(isset($_POST['options'])){
$epinum = $_POST['options'];
}
?>
<form action="" method="post">
<SELECT class='listofepisodes' NAME='options' onchange='this.form.submit()' size='1200'>
<?PHP
$options=mysql_query("SELECT * FROM table");
while($option=mysql_fetch_array($options)) {
$image=$option['link'];
$number=$option['number'];
?>
<option value="<?PHP echo $image; ?>" <?php if(isset($_POST['options']) && $_POST['options']==$image) echo 'selected'; ?>>Option <?PHP echo $number; ?></option>
<?PHP } ?>
</SELECT>
</form>
<iframe name="iframe" src="<?PHP echo $epinum; ?>" height="388" width="640" frameborder="1" allowfullscreen></iframe>

关于javascript - POST 后选择 ="selected"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30085196/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com