$("#test > div > div.row-fluid > table > tbody > tr > td:nth-child(3)").after("<td><i class='fa fa-plus-square-o'></i></td>");
$("#test > div > div.row-fluid > table > tbody > tr > td:nth-child(4)").click(function()
{
if ($("#test > div > div.row-fluid > table > tbody > tr > td:nth-child(4) > i").hasClass("fa fa-plus-square-o")){
$(this).replaceWith("<td><i class='fa fa-minus-square-o'></i></td>");
}
if ($("#test > div > div.row-fluid > table > tbody > tr > td:nth-child(4) > i").hasClass("fa fa-minus-square-o")){
$(this).replaceWith("<td><i class='fa fa-plus-square-o'></i></td>");
}
});
這是我有的代碼。第一個if
可以工作,但在更改之後,但如果我想將其更改回去,則第二個if
不起作用。jQuery:問題與如果
謝謝!
只是假設這是一個X-Y的問題,如果你想切換特定元素的類,有更好的方法。 –
您正試圖「翻轉它」,然後立即將其翻轉回來? – mcsilvio
@mcsilvio,不是馬上,而是當我想要。 –