Validating css color names

前端 未结 7 1993
孤城傲影
孤城傲影 2020-12-09 16:15

I\'ve written a jQuery plugin that accepts css colors for some of its parameters.

I want to validate them. If it was just a hex or rgb value I could do that with a r

7条回答
  •  借酒劲吻你
    2020-12-09 16:48

    function test(myColor) {
      var valid = $('#test').css('color');
    
      $('#test').css('color', myColor);
    
      if (valid == $('#test').css('color')) alert("INVALID COLOR");
      else {
        alert("VALID");
        $('#test').css('color', valid);
      }
    }
    
    
    test("TATATA");
    test("white");
    
    
    
    asdasdasdasd

    It is hastily written but it works.

提交回复
热议问题