
radio是html中的单选项标签,通常放置于form表单中使用,value属性是标签的值;
获得值得两种方式:
一是在页面中通过javascript来获得:为radio加id属性,然后通过getElementsById(id名')value得到;
二是使用表单的action属性传值,使用PHP为通过get或者post方法传给某页面,使用$_GET['name名']或$_POST['name名']来获得。
1、定义一个radio节点
<input type='radio'/>2、通过过滤器获取选中的radio
var selectR = $('input:radio:checked');//input表示标签是input,:radio表示type是radio,:checked表示是选中3、通过val获取选中的值
var v =selectRval();//获取选中的值1,获取RadioGroup控件:
RadioGroup radioGroup = (RadioGroup)findViewById(RidmyRadioGroup);
2,获取RadioButton控件;
RadioButton radioButton = (RadioButton)findViewById(radioGroupgetCheckedRadioButtonId());
3,获取选中的radio的值:
String text = radioButtongetText()toString();
4,为radioGroup添加监听事件,用来监听组件内部的事件响应:
radioGroupsetOnCheckedChangeListener(new RadioGroupOnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//在这个函数里面用来改变选择的radioButton的数值,以及与其值相关的 //任何 *** 作,详见下文
selectRadioBtn();
}
})
;
5,在onCreat中需要初始化上面的四条信息;
6,整体的使用样例:
布局文件xml中的内容:
<RadioGroup
android:id="@+id/sex_group"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="男"/>
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"/>
</RadioGroup>
代码实现:
private RadioGroup mSex_group;
private RadioButton mMale;
private RadioButton mFemale;
private String sexName;
mSex_group = (RadioGroup) findViewById(Ridsex_group);
mMale = (RadioButton) findViewById(Ridmale);
mFemale = (RadioButton) findViewById(Ridfemale);
mSex_groupsetOnCheckedChangeListener(new RadioGroupOnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (mMalegetId() == checkedId) {
sexName = mMalegetText()toString();
} else if (mFemalegetId() == checkedId) {
sexName = mFemalegetText()toString();
}
}
});
以上就是关于PHP代码怎么获取radio中的value值全部的内容,包括:PHP代码怎么获取radio中的value值、如何通过jquery获取选中按钮的radio的value值、如何获取RadioGroup中RadioButton的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)