当前位置: 首页 > 图文教程 > 网络编程 > Javascript > jquery select(列表)的操作(取值/赋值)

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 jquery select(列表)的操作(取值/赋值)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 259 ::
收藏到网摘: n/a

因为工作的原因,从上周开始接触了jquery,以前我是自己写js的函数库,把一些常用的的方法写成函数,现在学习了jquery,发现还真是方便。不尽简洁了很多。用Ajax很方便,而且还可以很方便创造一些特效。 jquery的使用方法,看了jquery_api帮助文档和官方的文档,基本所有的用法都可以找到。
但却没有找到对<select>列表的操作。
jquery对<select>的操作比较麻烦,我把常用的收集如下:
1.获取选中值:$("select[@id='pagesize_slt'] option[@selected]").val();//-----pagesize_slt是<select>的id
2.设置选中项:$("select[@id='pagesize_slt']")[0].selectedIndex = 1;//-----<select>的index从0开始,所以1是第二项
很奇怪的是,我是用id来获取的,应该是唯一值,但$("select[@id='pagesize_slt']").selectedIndex = 1;是不对的。必须加[0]。也就是说,$("select[@id='pagesize_slt']")返回的其实是一个数组。这点需要注意。