Chinaunix首页 | 论坛 | 博客
  • 博客访问: 610364
  • 博文数量: 96
  • 博客积分: 1464
  • 博客等级: 上尉
  • 技术积分: 1539
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-12 23:24
文章分类

全部博文(96)

文章存档

2013年(29)

2012年(53)

2011年(14)

分类: 系统运维

2012-05-26 21:53:28

在系统界面开发中,有时要用到单选项,比如:性别只能是男或女。在flex中可以用radiobuttongroup来搞定,如下所示:

点击(此处)折叠或打开

  1. <fx:Declarations>
  2.         <s:RadioButtonGroup id="radiogroup1"   click="radiogroup1_change()" />
  3. </fx:Declarations>

  4. <s:RadioButton id="button_xm" label="姓名" groupName="radiogroup1" fontSize="12"/>
  5. <s:RadioButton id="button_zgh" label="职工号" groupName="radiogroup1" fontSize="12"/>
  6. lblSelectedText" height="23"  verticalAlign="middle"/>

  7. <fx:Script>
  8.     <![CDATA[
  9. private function radiogroup1_change():void
  10.      {
  11.             lblSelectedText.text = "Your choice is: "+radiogroup1.selection.label;  
  12.       }
  13.     ]]>
  14. </fx:Script>

上面的方法解决了单选问题,但还有不足,就是无法取消选项。下面的代码解决了此问题:
即在每个radiobutton上调用一个click属性把问题留给javascript解决

点击(此处)折叠或打开

  1. <fx:Script>
  2.     <![CDATA[
  3.         private var lastradiobut:Object = null;
  4. protected function radiobutton1_clickHandler(event:MouseEvent):void
  5.             {
  6.                 // TODO Auto-generated method stub
  7.                 if(lastradiobut==event.currentTarget)
  8.                 {
  9.                     radiogroup1.selection = null;
  10.                 }
  11.                 lastradiobut = event.currentTarget;
  12.                 
  13.                 if(radiogroup1.selection==null){
  14.                     lastradiobut = null;
  15.                     if(_obj.hasOwnProperty("zgh"))
  16.                         delete _obj.zgh;
  17.                     if(_obj.hasOwnProperty("xm"))
  18.                         delete _obj.xm;
  19.                 }else{
  20.                     if(radiogroup1.selection.label=="姓名"){
  21.                         _obj.xm=txtipt_xmZgh.text;
  22.                         if(_obj.hasOwnProperty("zgh"))
  23.                             delete _obj.zgh;
  24.                     }
  25.                     else if(radiogroup1.selection.label=="职工号"){
  26.                         _obj.zgh=txtipt_xmZgh.text;
  27.                         if(_obj.hasOwnProperty("xm"))
  28.                             delete _obj.xm;
  29.                     }
  30.                 }
  31.             }
  32.             
  33.     ]]>
  34. </fx:Script>

  35. <fx:Declarations>
  36.         <s:RadioButtonGroup id="radiogroup1"/>
  37. </fx:Declarations>
  38. <s:RadioButton id="button_xm" label="姓名" groupName="radiogroup1" fontSize="12"
  39.                          click="radiobutton1_clickHandler(event)"/>
  40. <s:RadioButton id="button_zgh" label="职工号" groupName="radiogroup1" fontSize="12"
  41.                          click="radiobutton1_clickHandler(event)"/>
  42. <s:TextInput id="txtipt_xmZgh" x="463" y="3" width="134" height="22" enabled="true"
  43.                          textAlign="left"/>













阅读(4768) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~