更新了我想要实现的代码示例。featuresToggle 甚至会触发复选框单击事件,然后应该在#featured-icon 上切换 css 类,但它不会添加该类。
<a class='favorite-btn' onclick="featuredToggle()">
<span id='featured-icon' class="glyphicon glyphicon-star"></span>
<input id="featured-toggle" type="checkbox" data-bind="checked: featured"/>
</a>
function featuredToggle() {
$("#featured-toggle").trigger('click');
$("#featured-icon").toggleClass('featured');
}