jQuery 如果边框颜色和边框宽度 =

标签 jquery html css

我正在尝试遍历多个 div 并找到周围带有蓝色边框的那些。然后,如果该 div 有蓝色边框,请查看它是否包含任何带有蓝色边框或边框宽度为 3px 的 div。如果主 div 有蓝色边框但没有带有蓝色边框或边框宽度为 3px 的 div,则附加一些文本。

我的 jQuery 正在努力寻找带有蓝色边框的主 div,但找不到里面有蓝色边框或边框宽度为 3px 的 div。

这是我的 jQuery

$('.decNode').each(function (e) {
        if ($(this).css('border-color') == 'rgb(0, 0, 255)') {
            console.log('There is a decNode with blue border');
            $('div[id*=RulesBox]').each(function () { console.log($(this).css('border-width'))});
            if ($(this).find('div[id*=RulesBox]').css('border-width') == '3px') {
                console.log('There is a RulesBox with blue border');
                $(this).find('.decNodeHeader h2').append(' - <span style="color:red;">RULES NOT MET</span>');
            }
            else {
            }                
        }
        else {
            //console.log('No decNode with a border');
        }

我的HTML是这样的

<div id="DecNode3011" class="decNode draggable ui-draggable" style="border:3px solid rgb(0, 0, 255);"">
  <div class="decNodeHeader">
    <div style="padding: 12px 12px 0px 12px;"><h2>Div Header Text</h2></div>
  </div>
  <div>
    <div id="RulesContainer7493">
              <div id="RuleSet233105">
                <div id="RulesBox233105" style="border: 1px solid #999999; background-color: #ffffff; padding-top: 8px;">
                  Rule Not Met
                </div>
              </div>
              <div id="RuleSet233106">
                <div id="RulesBox233106" style="border: 3px solid #0000FF; background-color: #ffffff; padding-top: 8px;">
                  Rule Met
                </div>
              </div>
            </div>
  </div>
</div>

最佳答案

你的 jquery 有问题。我已经修复它并添加了下面的代码。

$('.decNode').each(function (e) {
  if ($(this).css('border-color') == 'rgb(0, 0, 255)') {
     console.log('There is a decNode with blue border');
     $('div[id*=RulesBox]').each(function () {                            console.log($(this).css('border-width'));
       if ($(this).css('border-width') == '3px') {
         console.log('There is a RulesBox with blue border');
         $('.decNodeHeader h2').append(' - <span style="color:red;">RULES NOT MET</span>');
       }
       else {
         
       }                   
     });
    
                    
   }
   else {
            //console.log('No decNode with a border');
   }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="DecNode3011" class="decNode draggable ui-draggable" style="border:3px solid rgb(0, 0, 255);"">
  <div class="decNodeHeader">
    <div style="padding: 12px 12px 0px 12px;"><h2>Div Header Text</h2></div>
  </div>
  <div>
    <div id="RulesContainer7493">
              <div id="RuleSet233105">
                <div id="RulesBox233105" style="border: 1px solid #999999; background-color: #ffffff; padding-top: 8px;">
                  Rule Not Met
                </div>
              </div>
              <div id="RuleSet233106">
                <div id="RulesBox233106" style="border: 3px solid #0000FF; background-color: #ffffff; padding-top: 8px;">
                  Rule Met
                </div>
              </div>
            </div>
  </div>
</div>

关于jQuery 如果边框颜色和边框宽度 =,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56958063/

相关文章:

javascript - 需要在变量饼 Highcharts 上放置边框吗?

javascript - 通过 jQuery 修改 CSS 高度的意外行为

javascript - react redux 打印 Prop 的方式

html - 从用户体验的角度来看,什么反对单页应用程序?

html - ID内的ID是否有必要有一个CSS选择器?

css - 在样式中引用类

Javascript 更改下拉列表值

javascript - 如何将动态添加的内容存储到数据库

javascript - 如何读取 JSON 数据并将其与变量进行比较

javascript - 使用 jQuery 切换 CSS 类