jquery对strutrs2 <s:radio>标签的设置和取值
今天郁闷了1小时。
需求是这样的:
<s:radio list="#{0:'男',1:'女'}" value="member.sex" id="sex_id" name="member.sex" listKey="key" listValue="value" onclick="checkSex(this.value)"></s:radio>
这个标签 在页面源代码是这样的
<input type="radio" name="member.sex" id="sex_id0" value="0" onclick="checkSex(this.value)"/><label for="sex_id0">男</label>
<input type="radio" name="member.sex" id="sex_id1" checked="checked" value="1" onclick="checkSex(this.value)"/><label for="sex_id1">女</label>
现在想 点击 男或女单选按钮的时候 想对选中的某项进行“赋值" val 其实正确思路应该是 “选中” selected
结果直接错误的写法是这样的:
function checkSex(val){
$("#sex_id").val(val);
//对选中的取值
var value = $("#sex_id").val();
//这里的value一直是undefined,折腾了半天
}
后来找看了博客
http://heisetoufa.iteye.com/blog/1674657
http://blog.sina.com.cn/s/blog_7b87efa501015ho3.html
改为
function checkSex(val){
if(val!=null&&val!=""){
//对某项赋值
$("#sex_id"+val).attr("checked",true);
//$("#payStatus00").attr("checked",true);
}
//对选中的取值
var value = $("input[name='member.sex'][type='radio'][checked]").val();
//var val = $("input[name=''member.sex'']:checked").val();//获得选中的radio的值,也可以这样
}
//得出结论
不就是所有控件都是val的 很多都是selected
jquery对strutrs2 <s:radio>标签的设置和取值的更多相关文章
- radio的选中设置以及取值。
前台:<input type=" id="tg" name="state"/> <a style="cursor:poin ...
- struts2 页面标签或ognl表达式取值--未完待续
一.加#号取值和不加#号取值的解说 1.s:property 标签——value属性使用事项 1)涉及问题:取值时什么时候该加#,什么时候不加? 2)介绍 <s:property value=& ...
- js localStorage 设置和取值
定义 Storage 对象,对象有get(取值), set(设置), add(加入新值)三个方法 const Storage = {} Storage.get = function (name) { ...
- Jquery中的CheckBox、RadioButton、DropDownList的取值赋值实现代码
随着Jquery的作用越来越大,使用的朋友也越来越多.在Web中,由于CheckBox. Radiobutton . DropDownList等控件使用的频率比较高,就关系到这些控件在Jquery中的 ...
- Jquery 中的CheckBox、 RadioButton、 DropDownList的取值赋值
1.获取选中值,三种方法都可以: $('input:radio:checked').val(): $("input[type='radio']:checked").val(); $ ...
- JQuery中对option的添加、删除、取值
jQuery获取Select选择的Text和Value: 1. $("#select_id").change(function(){//code...}); //为Selec ...
- Matlab绘图基础——axis设置坐标轴取值范围
peaks; axis tight %Set the axis limits to equal the range of the data axis square axis 'auto x' % ...
- cookie的设置与取值
设置cookie function cookie(key, value, options) { let days let time let result // A key and value were ...
- web.config设置和取值
博客园中有一篇文章对web.config的结构做了很详细的介绍,原文见 http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.htm ...
随机推荐
- java MVC架构-spring mvc,struct2(理解)
MVC架构实现基础: 基于filter或者servlet实现请求地址分析,如果需要控制类处理请求,则调用相应的控制类.调用控制类时,根据配置文件初始化控制类相关的参数.数据库连接可持久化存在.控制类处 ...
- matches field ID value 17.9.1 The LABEL element
https://www.w3.org/TR/html401/interact/forms.html#edef-LABEL <!ELEMENT LABEL - - (%inline;)* -(LA ...
- filesort
- Raft
http://thesecretlivesofdata.com/raft/ https://github.com/coreos/etcd 1 Introduction Consensus algo ...
- mybatis 中#{}与${}的区别 (面试题)
MyBatis/Ibatis中#和$的区别 1. #将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号. 如:order by #user_id#,如果传入的值是111,那么解析成sql时的 ...
- linux ntp时间同步
linux ntp时间同步 一.搭建时间同步服务器1.编译安装ntp serverrpm -qa | grep ntp若没有找到,则说明没有安装ntp包,从光盘上找到ntp包,使用rpm -Uvh n ...
- scandir 使用示例
int filter_fn(const struct dirent * ent) { if (ent->d_type != DT_REG) return 0; r ...
- PHP其它常用函数;<<<面向对象(OPP)的三大特性:封装、继承、加态:>>> <----面试题 ;构造方法、析构方法,魔术方法、set、get方法;静态;抽象类;接口
PHP其它常用函数: 赋值:$r->name = "元素"; 取值: echo $r->name; count() 计算数组中的元素数目或对象中 ...
- yii1.1.3主从(多从)、读写分离配置
从新配置main.php片段 代码如下 ----------------------------------------------------------- 'db'=>array( 'con ...
- MongoDB上的索引
1. 将索引建在number键上名为nameIndex并且为正序索引({number:-1}为倒序索引) 如: db.list名.ensureIndex({number:1},{name:" ...