简体   繁体   English

jQuery如果value大于1,如何更改CSS

[英]jQuery How to change CSS if value is greater than 1

Alright so there is already an answer to this but I am trying to do the exact same thing, but I've same another css class to "call" this script. 好吧所以已经有了答案,但我正在尝试做同样的事情,但我有同样的另一个css类来“调用”这个脚本。

Example: I have this calling to messages, when the content inside messages is over 0 it will change the background color, what I would like to do is change the bottom border on ".root_panel" to the same color as the messages. 示例:我对消息进行调用,当消息内的内容超过0时,它将更改背景颜色,我想要做的是将“.root_panel”的底部边框更改为与消息相同的颜色。 I'm very new to JavaScript. 我是JavaScript的新手。

Script: 脚本:

$(document).ready(function () 
{
   $(".messagess").each(function() 
    {
      var el = $(this);
      var value = parseFloat(el.text());
      if (value > 0) 
         {
            el.css("background","#6E8A75").css("color","#fff");
         }
      else
         {
            el.css("color", "#fff"); 
         }
    }); 
});

see my answer as a reference, hope this help. 看到我的答案作为参考,希望这个帮助。

 $(document).ready(function(){ $("button").click(function(){ if($("#zero").val() <= 0){ $(".root_panel").css({ 'border-bottom' : '2px solid red' }); }else if($("#zero").val() === "1"){ $(".root_panel").css({ 'border-bottom' : '2px solid blue' }); }else if($("#zero").val() === "2"){ $(".root_panel").css({ 'border-bottom' : '2px solid green' }); }else if($("#zero").val() === "3"){ $(".root_panel").css({ 'border-bottom' : '2px solid violet' }); }else if($("#zero").val() === "4"){ $(".root_panel").css({ 'border-bottom' : '2px solid pink' }); }else if($("#zero").val() === "5"){ $(".root_panel").css({ 'border-bottom' : '2px solid gray' }); }else if($("#zero").val() === "6"){ $(".root_panel").css({ 'border-bottom' : '2px solid black' }); }else if($("#zero").val() === "7"){ $(".root_panel").css({ 'border-bottom' : '2px solid orange' }); }else{ $(".root_panel").css({ 'border-bottom' : 'none' }); } }); }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="root_panel" style="overflow: auto;">root panel</div> <button>button</button> <input type="text" id="zero" /> 

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

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