惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
U
Unit 42
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
G
Google Developers Blog
Recent Announcements
Recent Announcements
B
Blog RSS Feed
罗磊的独立博客
博客园 - Franky
J
Java Code Geeks
S
SegmentFault 最新的问题
D
DataBreaches.Net
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
腾讯CDC
博客园_首页
美团技术团队
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
GbyAI
GbyAI
The Cloudflare Blog
aimingoo的专栏
aimingoo的专栏

博客园 - Xia.CJ

C# 委托 node.js中连接mongodb(Please ensure that you set the default write...)解决办法 node.js api解读之file system模块 Node.js小技巧 在windows上安装新版node.js-node.js学习笔记 Asp.Net MVC部暑托管服务器iis7提示403错误解决方法 mvc3中使用unobtrusive时,ajax更新加载页面后验证失效解决方法 ashx中使用HttpContext.Current.Session ,出现未将对象引用设置到实例上 搜索引擎(google/百度)高级指令 在mvc3中使用uploadify上传组件User.isAuthenticated等于false解决方法 MVC中用Html.RenderPartial还是Html.RenderAction或者Html.Partial-Xia.CJ 在_Layout使用Html.RenderAction的问题-MVC3(Razor)问题 无法删除此对象,因为未在 ObjectStateManager 中找到它-entity framework删除时 Javascript数组(array)操作 序列化类型 System.Data.Entity.DynamicProxies 的对象时检测到循环引用 entity framework(EF)_code first复杂类型(Complex Types)问题 entity framework多对多关系查询 JQuery获取checkbox值,checkbox全选,操作checkbox JQuery动态创建DOM、表单
JQuery操作Select
Xia.CJ · 2011-09-30 · via 博客园 - Xia.CJ

JQuery操作Select

因为很简单,就直接粘贴代码了,别忘记引用 JQuery包

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JQuery操作Select</title>
<script type="text/javascript" language="javascript" src="../jquery-1.6.1.min.js"></script>
<script type="text/javascript" language="javascript">
$(
function(){
//默认选中指定value的值(这里value值为3)
$('#country option[value=3]').attr('selected',true);
//这样子也可以
//$('#country option[value=3]').attr('selected','selected');
$('#btn_getvalue').click(function(){
var icountry_id=$('#country').val();
var scountry_name=$('#country option:selected').text();
alert(
"countryId="+icountry_id+"\n 城市名="+scountry_name);
});
})
</script>
</head>

<body>
<small>
默认选中指定value=3(福建省)的值</small>
<br />
<select id="country">
<option value="0">请选择</option>
<option value="1">北京市</option>
<option value="2">上海市</option>
<option value="3">福建省</option>
<option value="4">浙江省</option>
</select><br />
<input type="button" id="btn_getvalue" value="点我获取country的值" />
</body>
</html>

 创建Select详见我另一篇文章,也很简单。

JQuery动态创建DOM、表单元素