<tr>
<th class="current-state running">
<i class="iconfont"></i>
<span></span>
</th>
<th class="operation">
<button class="state-btn">暂停</button>
<button>配置</button>
<button>更多操作</button>
</th>
</tr>
running为正在运行,pause为已暂停,icon和span文字通过css添加。
如何通过点击state-btn控制同一行中的.current-state的状态?
<tr>
<th class="current-state">
<i class="iconfont"></i>
<span></span>
</th>
<th class="operation">
<button class="state-btn"></button>
<button>配置</button>
<button>更多操作</button>
</th>
</tr>
$('.state-btn').click(function(){
$(this).parent('.operation').parent().toggleClass('running');
});
已经自己解决!获取点击button的父元素的父元素,添加class.running,默认状态下,icon、span文本、button文本均通过css伪类content控制,给tr增加.running,running状态下,更换icon和文本就好了!