【问题标题】:How do display checked value in checkbox on Google plus style popup box?如何在 Google plus 样式弹出框的复选框中显示选中的值?
【发布时间】:2012-04-06 19:26:02
【问题描述】:

在阅读 Stackoverflow 上的这篇文章后 Google plus popup box when hovering over thumbnail? 我被启发将它添加到我的网站上。

我设法做到了,脚本将联系人添加到我的数据库中。到目前为止很棒!

但是,我的问题(也出现在示例中)是它没有显示“选中”值...所以用户永远不会知道他们是否已经将它们添加到列表中。

用 PHP 显示检查值的正确方法是什么?

这是我的html代码:

<ul style="list-style: none;padding:2px;">
<li style="padding:5px 2px;">
<input type="checkbox" id="Friends" name="circles" value="Friends" '.$checked1.'/>
            Friends
</li>
<li style="padding:5px 2px;">
<input type="checkbox" id="Following" name="circles" value="Following" '.$checked2.'/>Following
</li>
<li style="padding:5px 2px;">
<input type="checkbox" id="Family" name="circles" value="Family" '.$checked3.'/>
            Family
</li>
<li style="padding:5px 2px;">
<input type="checkbox" id="Acquaintances" name="circles" value="Acquaintances" '.$checked4.'/>
            Acquaintances
</li>
</ul>

而我的 PHP 代码是:

if($circle_check_friends>0) {
$ckecked1='checked=""';
} else if ($circle_check_following>0) {
$ckecked2='checked=""';
} else if ($circle_check_family>0) {
$ckecked3='checked=""';
} else if ($circle_check_acquaintances>0) {
$ckecked4='checked=""';
} else if ($circle_check_friends=0) {
$ckecked1='';
} else if ($circle_check_following=0) {
$ckecked2='';
} else if ($circle_check_family=0) {
$ckecked3='';
} else if ($circle_check_acquaintances=0) {
$ckecked4='';
}

我迷路了,因为这没有给我想要的结果......即根据用户的选择显示检查的值。

非常感谢您的帮助

提前谢谢大家

乔治

【问题讨论】:

  • 将所有代码粘贴到jsfiddle.net,以便我们轻松修复

标签: php ajax checkbox google-plus


【解决方案1】:

试试这个:

$checked1 = ($circle_check_friends == 1) ? 'checked=""' : false;
$checked2 = ($circle_check_following == 1) ? 'checked=""' : false;
$checked3 = ($circle_check_family == 1) ? 'checked=""' : false;
$checked4 = ($circle_check_acquaintances == 1) ? 'checked=""' : false;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 2022-06-23
    • 2014-04-13
    • 1970-01-01
    • 2019-03-06
    相关资源
    最近更新 更多