|
<select id="stsoft" name="stsoft">
<option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select> <table id="datatable" border="0" cellpadding="0" cellspacing="0"> <tr align="left"> <th>行号</th> <th>类型</th> <th>操作</th> </tr> <tr id="template"> <td class="RowId"> </td> <td class="SoftType"> </td> <td class="update"> </td> </tr> </table> |
|
$(".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被选中项的文本
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”); |