【发布时间】:2016-05-24 10:29:09
【问题描述】:
我试图在我的 ui 中显示下拉列表的选定值。
<tr class="odd" rowid="1" height="50">
<td>
<select disabled name="item[]" id="item_1" class="dropdown required" tabindex="18">
<?php echo $itemOption;?>
</select>
</td>
<td >
<a href="javascript:void(0);" style="height:40px; width:45px" class="button add_new_row ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-focus" data-role="button" ><span class="ui-button-text" style="padding:0;" disabled>+</span></a>
</td>
</tr>
在 jquery 中,我需要获取这个 tr 来复制我的下拉列表。这是我的jQuery
var thisRow = $(this).closest('tr');
newid=parseInt(thisRow.attr('rowid'))+1;
var count = $('.dataTable input.timepicker').length + 1;
newRow = thisRow.clone(true).insertAfter(thisRow).find('input').val('').end().
但是我在 thisRow 中没有定义。可能是什么原因。有人请纠正我。
【问题讨论】:
-
this指的是什么? -
我正在尝试获取当前对象。这意味着当前页面。不知道是不是写的。
-
@django 但是什么返回
console.log(this);???您需要提供有关您发布的代码的更多上下文,因为没有人知道this指的是什么……也许您只需要var thisRow = $('tr[rowid=1]);。但还是要注意,因为这个TR有ID设置的后代(item_1),在DOM中添加克隆会导致无效的HTML标记,得到一些具有相同ID的多个元素
标签: javascript jquery html tags