利用jquery操作select下拉列表框
利用jquery操作select下拉列表框,功能是通过点击事件动态复制一个select到table的td中,并利用td包含的文本内容找到对应的select选中项,代码如下:
HTML:
<!--下拉框-->
<select id="stsoft" name="stsoft">
<option value="1">11</option>
<option value="2">22</option>
<option value="3">33</option>
<option value="4">44</option>
<option value="5">55</option>
<option value="6">66</option>
</select>
<table id="datatable" border="0" cellpadding="0" cellspacing="0">
<thead>
<tr align="left">
<th>
行号</th>
<th>
软件类型</th>
<th>
操作</th>
</tr>
</thead>
<tr id="template">
<td class="RowId">
</td>
<td class="SoftType">
</td>
<td class="update">
</td>
</tr>
</table>
js:
$(".update").click(function(){
var soft = $(".SoftType").text();
$(".SoftType").html($("#stsoft").clone());
for(var i=0; i<$(".SoftType select option").length; i++){
if($(".SoftType select")[0].options(i).text== soft){
$(".SoftType select")[0].selectedIndex = i;
}
}
var rowId = $(".RowId").text();
var content='\
<a href="javascript:void(0);" onclick="Update('+ rowId +');">更新</a> \
<a href="javascript:void(0);" onclick="Cencel('+ rowId +');">取消</a>\
';
$(".update").html(content);
});
其他有关select的取值或赋值方式:
获取select被选中项的文本
var item = $("select[@name= stsoft] option[@selected]").text();
select下拉框的第二个元素为当前选中值
$('#stsoft')[0].selectedIndex = 1;
获取value值
$('#stsoft').val();
设置value=1的项目为当前选中项
$("#stsoft").attr("value",“1”);
$('#stsoft').val(“1”);
--------------------------------------------------------------------
//获取第一个option的值
$('#test option:first').val();
//最后一个option的值
$('#test option:last').val();
//获取第二个option的值
$('#test option:eq(1)').val();
//获取选中的值
$('#test').val();
$('#test option:selected').val();
//设置值为2的option为选中状态
$('#test').attr('value','2');
//设置第一个option为选中
$('#test option:last').attr('selected','selected');
$("#test").attr('value' , $('#test option:last').val());
$("#test").attr('value' , $('#test option').eq($('#test option').length - 1).val());
//获取select的长度
$('#test option').length;
//添加一个option
$("#test").append("<option value='9'>ff</option>");
$("<option value='9'>ff</option>").appendTo("#test");
//添除选中项
$('#test option:selected').remove();
//指定项选中
$('#test option:first').remove();
//指定值被删除
$('#test option').each(function(){
if( $(this).val() == '5'){
$(this).remove();
}
});
$('#test option[value=5]').remove();
//获取第一个Group的标签
$('#test optgroup:eq(0)').attr('label');
//获取第二group下面第一个option的值
$('#test optgroup:eq(1)ption:eq(0)').val();
获
jquery操作select下拉框的多种方法(选中,取值,赋值等)_计算机软件及应用_IT/计算机_专业资料。Query 获取 Select 选择的 Text 和 Value: 语法解释: 1. $("#...
select 获取选中的下拉列表框的值 var select = docuement.getElementById("...[index].value; // 选中值 //使用JQuery获取select $("#selector").val()...
select 下拉列表的JS操作... 4页 免费 使用JS操作Select元素的... 5页 ...js 操作 select 下拉框 <select id="ddlResourceType" onchange="getvalue(...
select项目 静态select项目(可以通过服务器端脚本填充),可以直接使用$("#下拉框... jquery 下拉列表框 改变... 3页 免费 jquery下拉框联动 3页 免费 JQuery ...
jquery 获取下拉框值与select text_IT认证_资格... 设置 select option 项: $("#select_id")....我想了想用网页特效可以获 得,这里用了比较流行的...
设置EXCEL下拉列表框的3... 8页 免费 利用jquery操作select下... 2页 1...(select)的操作这篇文章,主要是关于 javascript 和 select 相关的最基本方法,以...
代码要点: 1、使用 JQuery 给 select 标签添加 ...JQuery 的下拉框级联操作</title> 11.<script type... jquery 下拉列表框 改变... 3页 免费 制作简单...
jquery操作 单选、复选、下拉操作代码_IT/计算机_...(); select 下拉框的第二个元素为当前选中值 $(...2014 Baidu 使用百度前必读 文库协议...
jquery select操作大全_计算机软件及应用_IT/计算机...--下拉框--> <select id="selectTest" name="...
//***/ //使用方法 onkeyup="drop_downListen('要应用此功能的select下拉列表的ID',event)" //***/ //1、汉字转换 对照值数组 字库形式 可以手动增加字库...
热门文档