我单击此按钮后如何访问此元素...经过多次尝试仍然不知道如何执行此操作...这是我的示例...因为我想尝试此方法http://jsfiddle.net / yXcZG / 53 /但以我自己的方式...
<div id="modalBodyContact" class="modal-body">
<table width="100%" cellspacing="0" class="display" id="contactsTable">
<tbody>
<tr>
<td>
<p data-id="5" class="contactInfo">123321</p>
</td>
<td class="pull-right">
<button data-id="5" class="edit" type="button">Edit</button>
<button data-id="5" class="delete" type="button">Delete</button>
</td>
</tr>
<tr>
<td>
<p data-id="6" class="contactInfo">123321</p> <---- I get this element after I click that EDIT BUTTON
</td>
<td class="pull-right">
<button data-id="6" class="edit" type="button">Edit</button> // <---- I CLICK THIS then ACCESS to <p>
<button data-id="6" class="delete" type="button">Delete</button>
</td>
</tr>
</tbody>
</table>
</div>
这就是我单击按钮时所做的...
$("#modalBodyContact").on('click', 'button.edit', function(){
var contact_id = $(this).data("id");
//im stuck here
});
编辑1
这是小提琴http://jsfiddle.net/mm6ce7t1/5
我要回<p data-id="5" class="contactInfo">5555</p>
不是5555
......怎么办?因为我想用文本框替换它。
[编辑]
在函数“ TBox”中,参数“ obj”不是对象,而是字符串,因此您需要传递对象而不是字符串。我再次更改了您的代码以接受对象,请看一下http://jsfiddle.net/mm6ce7t1/6/
$("#modalBodyContact").on('click', 'button.edit', function(){
var contact_id = $(this).data("id");
var p = $("#modalBodyContact").find("p[data-id='" + contact_id + "']");
console.log(p);
TBox(p);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句