doukong9982 2019-01-15 20:15
浏览 55

WooCommerce:添加自定义类以选择包装器

A short question: How can I add my custom class select-wrapper to the input wrapper when it only holds a select in it?

<span class="woocommerce-input-wrapper select-wrapper">
    <select name="billing_title" id="billing_title" class="select " data-placeholder="">
       <option value="1" selected="selected">Herr</option><option value="2">Frau</option>
    </select>
</span>

I can't find anything in the web which helps me to come forward with this topic.

  • 写回答

1条回答 默认 最新

  • doufan9805 2019-01-15 21:54
    关注

    You can use the following javascript code.

    <script type="text/javascript">
    var nodes = document.getElementsByClassName("woocommerce-input-wrapper");
    
    for(var i=0; i<nodes.length; i++) {
        var cnt = 0;
        for (let node of nodes[i].childNodes) {
    
          if(node.nodeName.toLowerCase() == 'select'){
            cnt++;
            break;
          }
    
        }
        if(cnt > 0)
        nodes[i].classList.add("select-wrapper");
    
    }
    </script>
    

    If you are using any js frameworks like jQuery, you can easily reduce the length of code to 2 or three lines.

    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真