Case-insensitive switch-case

前端 未结 3 650
余生分开走
余生分开走 2021-01-02 04:57

OK, so let\'s say I have this:

$(function() {
  $(\'#good_evening\').keyup(function () {
    switch($(this).val()) {
    case \'Test\':
      // DO STUFF HER         


        
相关标签:
3条回答
  • 2021-01-02 05:13
    switch($(this).val().toLowerCase()) {
        case 'test':
        // DO STUFF HERE          
        break;
    }
    
    0 讨论(0)
  • 2021-01-02 05:17

    Why not lowercase the value, and check against lowercase inside your switch statement?

    $(function() {
        $('#good_evening').keyup(function () {
            switch($(this).val().toLowerCase()) {
            case 'test':
            // DO STUFF HERE
            break;
            }
        });
    });
    
    0 讨论(0)
  • 2021-01-02 05:27

    Convert it to upper case. I believe this is how it is done, correct me if I am wrong... (dont -1 me =D )

    $(function() {
        $('#good_evening').keyup(function () {
                switch($(this).val().toUpperCase()) {
                case 'TEST':
                // DO STUFF HERE
                break;
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题