PHP代码怎么获取radio中的value值

PHP代码怎么获取radio中的value值,第1张

radio是html中的单选项标签,通常放置于form表单中使用,value属性是标签的值;

获得值得两种方式:

一是在页面中通过javascript来获得:为radio加id属性,然后通过getElementsById(id名')value得到;

二是使用表单的action属性传值,使用PHP为通过get或者post方法传给某页面,使用$_GET['name名']或$_POST['name名']来获得。

div id="wrap">

<input type="radio" name="payMethod" value="1" />支付宝

<input type="radio" name="payMethod" value="2" />财务通

</div>

获取一组单选按钮对象:var obj_payPlatform = $('#wrap input[name="payMethod"]');

获取被选中按钮的值 :var val_payPlatform = $('#wrap input[name="payMethod"]:checked ')val();

给你个例子看看吧:

value="1"

onclick="selType(thisvalue)"

checked="checked"/>1

value="2"

onclick="selType(thisvalue)"/>2

以上的两个单项按钮,具有相同的name

属性,不同的id,当要获取所选中的radio的值的时候,使用:requestgetParameter("same"),就取出了id的值,根据id的值就可以判断选中了哪个单选按钮了。

html 代码:

<form action="indexphp" method="post"><!--get方法也是可以的--!>

    <input type="radio" name="sex" value="f"> 女

    <input type="radio" name="sex" value="m"> 男

    <input type="submit" name="submit" value="提交"> 

</form

两个radio控件的name属性必须是一样的

indexphp代码:

$_POST['sex'];//就是单选框选中的  如果使用的是get方法,那么使用 $_GET['sex'];

上面的只是简单地例子,可以参考一下

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值、如何获取Web页面中radio按钮的值、jsp如何取到选中的radio中每一列的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/10094254.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存