如何显示被选中还是选中的单选按钮? [英] how to show the radio button is selected is still ticked?

查看:100
本文介绍了如何显示被选中还是选中的单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有2个单选按钮,当用户蜱任何它时,勾选单选按钮的值将被保存在通过AJAX的表,现在的问题是,当用户回来到页面,单选按钮不勾选,如何使选中的单选按钮显示为选中,让用户知道他之前选择?

这是我的code

 < UL>
    <李作风=列表样式类型:无;>
<分区对齐=中心类=radio_group>
    <输入类型=无线电ID =gallerymenustyle1级=元素电台NAME =gallerymenustyle []值=1/>图库链接 - 在我的网站的导航,显示一长廊链接< BR />
    <输入类型=无线电ID =gallerymenustyle2级=元素电台NAME =gallerymenustyle []值=2/>分类链接 - 在我的网站的导航,显示每一类单独的链接。
< / DIV>
    < /李>
< / UL>
 

解决方案

如果用户登录后,您应该查询数据库来获取按钮是否被选中的值。

如果没有登录,您可以使用会话ID的用户。虽然这仅适用直到用户关闭浏览器/会话过期。

 < PHP
$检查= 0;
//这个应该来自分贝
$检查= 1;
?>

< UL>
  <李作风=列表样式类型:无;>
    <分区对齐=中心类=radio_group>
      <输入类型=无线电ID =gallerymenustyle1级=元素电台NAME =gallerymenustyle []值=1<?PHP的,如果($检查== 1)打印('检查=检查')> />图库链接 - 在我的网站的导航,显示一长廊链接< BR />
      <输入类型=无线电ID =gallerymenustyle2级=元素电台NAME =gallerymenustyle []值=2<?PHP的,如果($检查== 1)打印('检查=检查')> />分类链接 - 在我的网站的导航,显示每一类单独的链接。
    < / DIV>
  < /李>
< / UL>
 

将检查第一个单选按钮

my app has 2 radio buttons, when user ticks any of it, the value of the ticked radio button gets saved in the table via ajax, now the problem is, when user gets back to the page, the radio button is not ticked, how to make the selected radio button appear as ticked, so that the user knows which he selected before ?

here's my code

<ul>
    <li style="list-style-type: none;">    
<div align="center" class="radio_group">
    <input type="radio" id="gallerymenustyle1" class="element radio" name="gallerymenustyle[]" value="1" /> Gallery Link - In the navigation of my website, display one "gallery" link<br />
    <input type="radio" id="gallerymenustyle2" class="element radio" name="gallerymenustyle[]" value="2" /> Category Links - In the navigation of my website, display a separate link to each category.
</div>
    </li>
</ul>

解决方案

If the user is logged in you should query the database to get the value whether the button was ticked.

If the user isn't logged in you could use the session id. Although this only works until the user closes his browser / the session expires.

<?php
$checked = 0;
// this should come from db
$checked = 1;
?>

<ul>
  <li style="list-style-type: none;">    
    <div align="center" class="radio_group">
      <input type="radio" id="gallerymenustyle1" class="element radio" name="gallerymenustyle[]" value="1" <?php if ($checked == 1) print('checked="checked"') ?>/> Gallery Link - In the navigation of my website, display one "gallery" link<br />
      <input type="radio" id="gallerymenustyle2" class="element radio" name="gallerymenustyle[]" value="2" <?php if ($checked == 1) print('checked="checked"') ?>/> Category Links - In the navigation of my website, display a separate link to each category.
    </div>
  </li>
</ul>

Will check the first radio button

这篇关于如何显示被选中还是选中的单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆