【发布时间】:2017-01-31 00:36:16
【问题描述】:
我在 td 中有一个带有按钮的表格,一旦我按下按钮,它就会将文本添加到 td。再次按下按钮后,我想删除 td 中的此文本。请注意,此按钮在表格中多次使用,因此是类属性。 我可以使用哪种方法来完成这项工作?
这是我的代码:
$(document).on('click', '.releasebutton', function () { // button class="releasebutton"
var label = $(this).text();
if (label == "Add") { // it is "Add" by default
$(this).text("Cancel");
$('.ReleaseTD').append("<br>" + "test"); // td class="ReleaseTD"
}
// the code above this works
else {
$(this).text("Add");
$('.ReleaseTD').remove("<br>" + "test");
// this obviously is wrong but this is where i would like the correct code
};
});
【问题讨论】:
标签: javascript jquery html