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 ...
随机推荐
- UItableview里面的header、footer
#import "ViewController.h" #import "MJRefresh.h" @interface ViewController () { ...
- laravel elixir
npm install npm install jquery --save //bootsrap3.36 与 jquery3不兼容,下载jquery时可能需要确定版本号 npm install jqu ...
- jsp页面直接编写csss
<style> .logoZL{ width:550px; float:right; text-align:right; padding-right:15px; margin-right: ...
- SQL2008全部数据导出导入两种方法【转】
方法一:生成脚本导出导入sql2008全部数据 第一步,右键要导出的数据库,任务--生成脚本 第二步,在设置脚本编写选项处,点击--高级(A),选择要编写脚本的数据的类型为:架构和数据 如果找 ...
- ubuntu如何开启root,如何启用Ubuntu中root帐号
jingyan.baidu.com/article/495ba84116104238b20ede62.html ubuntu如何开启root,如何启用Ubuntu中root帐号 | 浏览:8344 | ...
- .Net使用CDO发送邮件,需安装注册的组件
regsvr32 C:\Program Files\Common Files\System\ado\msado15.dll regsvr32 CDOEX.DLL
- Hbase中rowkey设计原则
1.热点问题 在某一时间段,有大量的数据同时对一个region进行操作 2.原因 对rowkey的设计不合理 对rowkey的划分不合理 3.解决方式 rowkey是hbase的读写唯一标识 最大长度 ...
- C/C++ 排序&&查找算法(面试)
一.排序 1.冒泡排序 void BubbleSort(int array[],int n) { ; ; ; ; ;i<n - ;i++) /*外循环控制排序的总趟数*/ { flag = ; ...
- Search in Rotated Sorted Array I
Search in Rotated Sorted Array I Suppose a sorted array is rotated at some pivot unknown to you befo ...
- 免费真机调试 -- Xcode7以上版本
刚新安装了Xcode7 , 据说这个版本可以免费真机调试,于是用了一个新的AppID测试了,发现真的可以免费真机调试了呢!新的appId账号(随便一个苹果手机账号就行),没有支付每年的99美刀,也没有 ...