例子,jquery下拉框赋值:
<%@ page language="java"pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>CNKI检索页面</title>
<!--去除连接<a href>下面的横线-->
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
.menu{
color: black;
}
</style>
<script type="text/javascript" src="<%=path %>/js/jquery.js"></script>
</head>
<body>
<form action="#" method="post">
<input type="hidden" name="dataBaseCode" id="dataBaseCode"/>
<table align="center" style="margin-top: 50px;">
<tr>
<td>
<img src="<%=basePath%>/images/logo.gif">
</td>
<td> </td>
<td>
<a href="#this" class="menu" onclick="getSearchTypeList('1')">文献</a>
<a href="#this" class="menu" onclick="getSearchTypeList('2')">期刊</a>
<a href="#this" class="menu" onclick="getSearchTypeList('3')">博硕文</a>
<a href="#this" class="menu" onclick="getSearchTypeList('4')">会议</a>
<a href="#this" class="menu" onclick="getSearchTypeList('5')">报纸</a>
<a href="#this" class="menu" onclick="getSearchTypeList('6')">年鉴</a>
<a href="#this" class="menu" onclick="getSearchTypeList('7')">百科</a>
<a href="#this" class="menu" onclick="getSearchTypeList('8')">词典</a>
<a href="#this" class="menu" onclick="getSearchTypeList('9')">统计年鉴</a>
<a href="#this" class="menu" onclick="getSearchTypeList('10')">外文期刊</a>
</td>
</tr>
<tr>
<td>
<select id="searchType" name="searchType" style="width: 180px;">
<option value="全文">全文</option>
<option value="主题">主题</option>
<option value="篇名">篇名</option>
<option value="作者">作者</option>
<option value="单位">单位</option>
<option value="关键词">关键词</option>
<option value="摘要">摘要</option>
<option value="参考文献">参考文献</option>
<option value="中图分类号">中图分类号</option>
</select>
</td>
<td colspan="2">
<input type="text" name="keyWords" size="80"/>
<input type="button" value="查询" />
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function changeStyle(){
$(".menu").css("background-color","white");
$(document).ready(function(){
$("a").click(function(){
$(this).css("background-color","blue");
});
});
}
function getSearchTypeList(code){
changeStyle();
$("#dataBaseCode").val(code);
var dataArr = null;
dataArr = [{name:"全文",value:"全文"},{name:"主题",value:"主题"},{name:"作者",value:"作者"},{name:"单位",value:"单位"},
{name:"关键词",value:"关键词"},{name:"摘要",value:"摘要"},{name:"参考文献",value:"中图分类号"}];
var searchType = $("#searchType");
searchType.css("display","block");
searchType.empty();
if(dataArr!=null){
for(var i=0;i<dataArr.length;i++){
var option = $("<option>").text(dataArr[i].name).val(dataArr[i].value);
searchType.append(option);
}
}
}
</script>
</body>
</html>
jquery操作下拉框(dropdownlist)取值赋值
jquery操作下拉框(dropdownlist),对dropdownlist进行取值赋值
1,获取选中项:
2,获取当前选中项的索引值:
3,获取当前option的最大索引值:
4,获取DropdownList的长度:
5,设置第一个option为选中值:
6,设置最后一个option为选中值:
7,根据索引值设置任意一个option为选中值:
8,设置Value=4 的option为选中值:
9,删除Value=3的option:
10,删除第几个option:
11,删除第一个option:
12,删除最后一个option:
13,删除dropdownlist:
14,在select后面添加一个option:
15,在select前面添加一个option:
16,遍历option: