简体   繁体   English

单选按钮 - 选择选项时更改图像边框颜色

[英]Radio Button - when option selected change image border color

i have a woocommerce website with filter for select color for the product.我有一个 woocommerce 网站,其中包含产品的 select 颜色过滤器。 3 colors: black, blue, white. 3 colors:黑色、蓝色、白色。 when they select the radio button it automaticly shows only the products available in that color.当他们点击 select 单选按钮时,它会自动仅显示该颜色的可用产品。 Each product image (thumbnail) have a border with a grey color.每个产品图像(缩略图)都有一个灰色边框。 my goal is to change the product image border color to the selected option.我的目标是将产品图像边框颜色更改为所选选项。

please advice:)请指教:)

So the major challenge is that WordPress destroys and the re-creates the blocks with the paintings so to circumvent that I added a delay of 600ms for the frames to update... This does work but it is not the best way to do it, of that I am sure.所以主要的挑战是 WordPress 破坏并重新创建带有绘画的块,以便规避我为帧更新添加了 600 毫秒的延迟......这确实有效,但它不是最好的方法,我确信这一点。

    radios = document.querySelectorAll('.jet-color-image-list__item');

    function getSetColor(index) {

        setTimeout(() => {
            buttons = document.querySelectorAll('.jet-color-image-list__row.jet-filter-row');
            holder = document.querySelectorAll('.elementor-jet-woo-products');
            frames = document.getElementsByClassName('jet-woo-product-thumbnail');

            for (i = 0; i < radios.length; i++) {
                if (radios[i].firstElementChild.checked) {
                    activeColor = buttons[i].firstElementChild.lastElementChild.firstElementChild.firstElementChild.style.backgroundColor;
                }
            }

            for (i = 0; i < frames.length; i++) {
                frames[i].style.borderColor = activeColor
            }
        }, 600);

    };

    for (i = 0; i < radios.length; i++) {
        radios[i].addEventListener('click', getSetColor);
    };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM