Jquery操作 Select
--------------------------------------------------------------------------------- 近日在使用jquery操作select下拉列表框时遇到了一些需要注意的地方,我想实现的功能是通过点击事件动态复制一个select到table的td中,并利用td包含的文本内容找到对应的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 content='\
<a href="javascript:void(0);" onclick="Update('+ rowId +');">更新</a> \
<a href="javascript:void(0);" onclick="Cencel('+ rowId +');">取消</a>\
';
$(".update").html(content);
});
其他有关select的取值或赋值方式: 引:http://www.cnblogs.com/fredlau/articles/1287290.html
|
浙公网安备 33010602011771号