在此示例中,我有一个 onclick 方法,我想将行从加号更改为减号。我还希望所有其他的都回到默认的 plus。有办法做到这一点吗?
$(document).ready(function() {
collapsed();
});
var collapsed = function(e, counter) {
$("#data tr").each(function() {
console.log('Data')
});
};
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<table id="data">
<tr>
<td>
<span class="btn tooltips btn-green" id="maincounter_1" data-maincounter="1" data-container="body" data-placement="top" onclick="collapsed(this,1)"><i id="icon_1" class="fa fa-plus"></i></span>
</tr>
<td>
<span class="btn tooltips btn-green" id="maincounter_2" data-maincounter="2" data-container="body" data-placement="top" onclick="collapsed(this,2)"><i id="icon_1" class="fa fa-plus"></i></span>
</tr>
<td>
<span class="btn tooltips btn-green" id="maincounter_1" data-maincounter="1" data-container="body" data-placement="top" onclick="collapsed(this,3)"><i id="icon_1" class="fa fa-plus"></i></span>
</tr>
<td>
<span class="btn tooltips btn-green" id="maincounter_1" data-maincounter="1" data-container="body" data-placement="top" onclick="collapsed(this,4)"><i id="icon_1" class="fa fa-plus"></i></span>
</tr>
<td>
<span class="btn tooltips btn-green" id="maincounter_1" data-maincounter="1" data-container="body" data-placement="top" onclick="collapsed(this,5)"><i id="icon_1" class="fa fa-plus"></i></span>
</tr>
</table>
像这样的事情可能会让你开始:
演示: