我试图在HTML5中的选定属性中插入一个PHP脚本,但语法失败了。
错误:"选定属性的值无效,因为当前架构不支持它"。
看起来是这样的。。。我该如何解决这个问题?谢谢
<div>
<label>Select author here:</label>
<select name="author">
<option value="">Select an author</option>
<?php foreach ($authors as $author): ?>
<option value="<?php htmlout($author['id']);?>"
selected="<?php ?>">
<?php htmlout($author['name']);?>
</option>
<?php endforeach; ?>
</select>
</div>
试试看:
<div>
<label>Select author here:</label>
<select name="author">
<option value="">Select an author</option>
<?php foreach ($authors as $author): ?>
<option value="<?php htmlout($author['id']);?>"
<?php echo $Your_Select_value == $author['id'] ? "selected" : '';?> >
<?php htmlout($author['name']);?>
</option>
<?php endforeach; ?>
</select>
</div>
selected
属性的正确值为selected
。因此,如果您希望将此属性应用于您认为当前选择的选项,请尝试以下操作(我假设存储所选作者id的PHP变量是$authorid
):
<div>
<label>Select author here:</label>
<select name="author">
<option value="">Select an author</option>
<?php foreach ($authors as $author): ?>
<option value="<?php htmlout($author['id']);?>"
<?php if ($author['id'] == $authorid) echo ('selected="selected"'); ?>
>
<?php htmlout($author['name']);?>
</option>
<?php endforeach; ?>
</select>
</div>