select multiple 取值问题 及jquery 的实现(type 是 select-multiple 不是 select-one )
来源:互联网 发布:哥布林升级数据 编辑:程序博客网 时间:2024/06/07 11:01
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
使用原生的javascript 脚本只能够取得第一个选中的第一个的值
var z = document.getElementById("mymultiple");
alert(z.value)
可以通过轮训所有selected 的option 取得所有选中的数值
jquery 或者第三方类库 会返回1,2,3,4 这样的值
jquery的实现如下:
通过判断select的 type 属性,如果是type: "select-multiple"(相对应的是select-one)
var value, option,
options = elem.options,
index = elem.selectedIndex,
one = elem.type === "select-one" || index < 0,
values = one ? null : [],
max = one ? index + 1 : options.length,
i = index < 0 ?
max :
one ? index : 0;
// Loop through all the selected options
for ( ; i < max; i++ ) {
option = options[ i ];
// IE6-9 doesn't update selected after form reset (#2551)
if ( ( option.selected || i === index ) &&
// Don't return options that are disabled or in a disabled optgroup
( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
// Get the specific value for the option
value = jQuery( option ).val();
// We don't need an array for one selects
if ( one ) {
return value;
}
// Multi-Selects return an array
values.push( value );
}
}
return values;
- select multiple 取值问题 及jquery 的实现(type 是 select-multiple 不是 select-one )
- 两个select multiple 多选 全选 取值 增加 删除 问题
- 两个select multiple 多选 全选 取值 增加 删除 问题
- 两个select multiple 多选 全选 取值 增加 删除 问题
- 两个select multiple 多选 全选 取值 增加 删除 问题
- multiple-select-master使用和取值
- UITableView 多选(Multiple Select)列表的实现
- select多选 multiple的使用
- jquery中 如何设置和取得 radio, checkbox, select, multiple select 的值
- jquery中 如何设置和取得 radio, checkbox, select, multiple select 的值 .
- jQuery学习: 实现select multiple左右添加和删除功能
- jQuery实现多选下来框(multiple select)
- Jquery实现select multiple左右添加和删除功能
- jQuery实现多选下来框(multiple select)
- select 中multiple属性
- bootstrap select multiple
- 不按Ctrl实现Multiple Select多选
- 不按Ctrl实现Multiple Select多选
- 给SHBrowseForFolder 添加“新建文件夹”按钮
- Android 记住密码和自动登录界面的实现(SharedPreferences 的用法)
- 段式存储管理
- JS获取当前时间或者把毫秒转换成yyyy-MM-dd的格式
- PHP-Fcgi下PHP的执行时间设置方法
- select multiple 取值问题 及jquery 的实现(type 是 select-multiple 不是 select-one )
- tomcat 的maven插件,配置端口和访问路径
- iOS学习之iOS沙盒(sandbox)机制和文件操作之NSFileManager(三)
- 滑动scrollview时,随距离改变属性的动画原理!(类似陌陌,网易,path个人属性界面的动画效果)
- android环境搭建
- ddd调试器中选项说明
- DLL导出函数名称改编的解决方法
- Ubuntu 12.04 LTStxt文件中文显示乱码
- iOS数据存储的四种方案对比