在默认问题上选中PHP/HTML单选按钮
基于PHP/MySQL创建单选按钮集 在默认情况下检查按钮时出现问题: 它看起来像什么: 守则:在默认问题上选中PHP/HTML单选按钮,php,html,mysql,radio,checked,Php,Html,Mysql,Radio,Checked,基于PHP/MySQL创建单选按钮集 在默认情况下检查按钮时出现问题: 它看起来像什么: 守则: $first = TRUE; if (mysql_num_rows($result)) { for ($j = 0; $j < mysql_num_rows($result); $j++) { $currentCat = mysql_result($result, $j, 'category'); if ($first == TRUE) {
$first = TRUE;
if (mysql_num_rows($result))
{
for ($j = 0; $j < mysql_num_rows($result); $j++)
{
$currentCat = mysql_result($result, $j, 'category');
if ($first == TRUE)
{
$first = FALSE;
echo "<input type='radio' name='createCat' value='$currentCat' checked='checked' />$currentCat checked";
}
else
{
echo "<input type='radio' name='createCat' value='$currentCat' />$currentCat ";
echo "non";
}
}
echo <<<_END
<br /><input type='submit' value='Create' /> $error
</form>
_END;
}
$first=TRUE;
if(mysql_num_行($result))
{
对于($j=0;$j echo将您的第一个选项更改为如下所示,它应默认为选中:
echo "<input type='radio' name='createCat' value='$currentCat' checked/>$currentCat checked";
删除=“checked”部分将解决问题。我看不出您最初在哪里设置了$first
。但是正如您从回音“checked”中看到的那样在第一个类别旁边。因此first显然设置为true。这有点奇怪。生成的HTML是什么?对我来说很好…涉及到Javascript吗?尝试不仅刷新页面,还可以单击地址栏中的URL并按enter键,这将确保表单处于初始状态。您在其他浏览中尝试过吗r?这里发生了一些奇怪的事情……如果你的PHP代码正是你在这里发布的代码,那么它应该可以工作。除了浏览器或浏览器插件的错误行为(或者只是需要像我上面提到的那样重置表单)之外,我能想到的唯一原因是打字错误。
echo "<input type='radio' name='createCat' value='$currentCat' checked/>$currentCat checked";
checked="checked"