我遇到了一個問題,希望有人可以提供幫助,我嘗試了一些不同的想法,但仍未解決。我已經使腳本使每個復選框的單擊都出現了一個復選框項目的列表,但是我要做的是單擊打開的列表項上的“ X”以取消選中匹配的輸入。我在這里有一個工作正常的CodePen,向您展示我的意思:https://codepen.io/nickelse/pen/dLoOVE感謝您的幫助,如果我需要進一步解釋,請告訴我:)我嘗試了一些不同的想法,但是無法正確地將其匹配到相應的輸入的邏輯。//demo example$(function() { var $allProducts = $(".js-refinement-link.input-checkbox"); var $selectedProductsListing = $(".selectedProducts"); $allProducts.on("click", function(e) { $selectedProductsListing.html( $allProducts .filter(":checked") .map(function(index, checkbox) { return ( '<li class="checked-items ' + checkbox.id + '" id="' + checkbox.id + '"><span>' + checkbox.id + "</span></li>" ); }) .get() .join("") ); });});.ul-reset { list-style: none; margin: 0; padding: 0;}.selectedProducts { display: flex; margin-left: -20px; margin-top: 40px;}.checked-items { padding-left: 20px;}.checked-items span { align-items: center; background: white; border: 3px solid tomato; border-radius: 6px; color: #333; display: flex; height: 36px; line-height: 1; padding-left: 10px; padding-right: 10px;}.checked-items span:after { color: red; width: 12px; content: 'X'; display: flex; align-items: center; justify-content: center; margin-left: 10px;}
取消選中具有匹配ID的復選框
滄海一幻覺
2021-04-08 14:10:18