js判断单选按钮是否被选中
2016-05-20 17:05
477 查看
第一,循环显示“资金类型”的单选结果集
<s:iterator value="#request.ziJinLeiXing" id="ziJinLeiXing" >
<input type="radio" class="easyui-validatebox" name="fdipXiangMuQueryBean.ziJinLeiXing" required="true"
value="<s:property value='#ziJinLeiXing.dictionaryCode'/>" <s:if test="#fdip.ziJinLeiXing==#ziJinLeiXing.name">checked="checked"</s:if> /><s:property value='#ziJinLeiXing.name'/>
</s:iterator><label style="color: red;"> <b>*</b></label>
第二,js判断资金类型是否被选中
//资金类型
var ziJinLeiXing=$("input[name='fdipXiangMuQueryBean.ziJinLeiXing']:checked").val();
if(ziJinLeiXing=="" || typeof(ziJinLeiXing)=="undefined"){
$.messager.alert("提示信息", "请选择资金类型");
return false;
}
第三,普及typeof 运算符
返回一个用来表示表达式的数据类型的字符串。
说明
typeof 运算符把类型信息当作字符串返回。typeof 返回值有六种可能: "number," "string," "boolean," "object," "function," 和 "undefined."
typeof 语法中的圆括号是可选项
在js里用到数组,比如 多个名字相同的input, 若是动态生成的, 提交时就需要判断其是否是数组.if(document.mylist.length != "undefined" ) {} 这个用法有误.
正确的是 if( typeof(document.mylist.length) != "undefined" ) {}
或 if( !isNaN(document.mylist.length) ) {}
typeof的运算数未定义,返回的就是 "undefined".
运算数为数字 typeof(x) = "number"
字符串 typeof(x) = "string"
布尔值 typeof(x) = "boolean"
对象,数组和null typeof(x) = "object"
函数 typeof(x) = "function
<s:iterator value="#request.ziJinLeiXing" id="ziJinLeiXing" >
<input type="radio" class="easyui-validatebox" name="fdipXiangMuQueryBean.ziJinLeiXing" required="true"
value="<s:property value='#ziJinLeiXing.dictionaryCode'/>" <s:if test="#fdip.ziJinLeiXing==#ziJinLeiXing.name">checked="checked"</s:if> /><s:property value='#ziJinLeiXing.name'/>
</s:iterator><label style="color: red;"> <b>*</b></label>
第二,js判断资金类型是否被选中
//资金类型
var ziJinLeiXing=$("input[name='fdipXiangMuQueryBean.ziJinLeiXing']:checked").val();
if(ziJinLeiXing=="" || typeof(ziJinLeiXing)=="undefined"){
$.messager.alert("提示信息", "请选择资金类型");
return false;
}
第三,普及typeof 运算符
返回一个用来表示表达式的数据类型的字符串。
说明
typeof 运算符把类型信息当作字符串返回。typeof 返回值有六种可能: "number," "string," "boolean," "object," "function," 和 "undefined."
typeof 语法中的圆括号是可选项
在js里用到数组,比如 多个名字相同的input, 若是动态生成的, 提交时就需要判断其是否是数组.if(document.mylist.length != "undefined" ) {} 这个用法有误.
正确的是 if( typeof(document.mylist.length) != "undefined" ) {}
或 if( !isNaN(document.mylist.length) ) {}
typeof的运算数未定义,返回的就是 "undefined".
运算数为数字 typeof(x) = "number"
字符串 typeof(x) = "string"
布尔值 typeof(x) = "boolean"
对象,数组和null typeof(x) = "object"
函数 typeof(x) = "function
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- Android学习笔记(二九):嵌入浏览器
- Android java 与 javascript互访(相互调用)的方法例子
- JavaScript演示排序算法
- javascript实现10进制转为N进制数
- 最后一次说说闭包
- Ajax
- 2019年开发人员应该学习的8个JavaScript框架
- HTML中的script标签研究
- 对一个分号引发的错误研究
- 异步流程控制:7 行代码学会 co 模块
- ES6 走马观花(ECMAScript2015 新特性)
- JavaScript拆分字符串时产生空字符的原因
- Canvas 在高清屏下绘制图片变模糊的解决方法
- Redux系列02:一个炒鸡简单的react+redux例子
- JavaScript 各种遍历方式详解
- call/apply/bind 的理解与实例分享