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

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 258 ::
收藏到网摘: 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']")返回的其实是一个数组。这点需要注意。