在系统界面开发中,有时要用到单选项,比如:性别只能是男或女。在flex中可以用radiobuttongroup来搞定,如下所示:
- <fx:Declarations>
- <s:RadioButtonGroup id="radiogroup1"
click="radiogroup1_change()" />
- </fx:Declarations>
- <s:RadioButton id="button_xm" label="姓名" groupName="radiogroup1" fontSize="12"/>
- <s:RadioButton id="button_zgh" label="职工号" groupName="radiogroup1" fontSize="12"/>
- lblSelectedText" height="23" verticalAlign="middle"/>
- <fx:Script>
- <![CDATA[
- private function radiogroup1_change():void
- {
- lblSelectedText.text = "Your choice is: "+radiogroup1.selection.label;
- }
- ]]>
- </fx:Script>
上面的方法解决了单选问题,但还有不足,就是无法取消选项。下面的代码解决了此问题:
即在每个radiobutton上调用一个click属性把问题留给javascript解决
- <fx:Script>
- <![CDATA[
- private var lastradiobut:Object = null;
- protected function radiobutton1_clickHandler(event:MouseEvent):void
- {
- // TODO Auto-generated method stub
- if(lastradiobut==event.currentTarget)
- {
- radiogroup1.selection = null;
- }
- lastradiobut = event.currentTarget;
-
- if(radiogroup1.selection==null){
- lastradiobut = null;
- if(_obj.hasOwnProperty("zgh"))
- delete _obj.zgh;
- if(_obj.hasOwnProperty("xm"))
- delete _obj.xm;
- }else{
- if(radiogroup1.selection.label=="姓名"){
- _obj.xm=txtipt_xmZgh.text;
- if(_obj.hasOwnProperty("zgh"))
- delete _obj.zgh;
- }
- else if(radiogroup1.selection.label=="职工号"){
- _obj.zgh=txtipt_xmZgh.text;
- if(_obj.hasOwnProperty("xm"))
- delete _obj.xm;
- }
- }
- }
-
- ]]>
- </fx:Script>
- <fx:Declarations>
- <s:RadioButtonGroup id="radiogroup1"/>
- </fx:Declarations>
- <s:RadioButton id="button_xm" label="姓名" groupName="radiogroup1" fontSize="12"
- click="radiobutton1_clickHandler(event)"/>
- <s:RadioButton id="button_zgh" label="职工号" groupName="radiogroup1" fontSize="12"
- click="radiobutton1_clickHandler(event)"/>
- <s:TextInput id="txtipt_xmZgh" x="463" y="3" width="134" height="22" enabled="true"
- textAlign="left"/>
阅读(4768) | 评论(0) | 转发(0) |