How do I programmatically set the value of a select box element using JavaScript?

后端 未结 17 1894
轮回少年
轮回少年 2020-11-22 06:33

I have the following HTML

17条回答
  •  心在旅途
    2020-11-22 06:53

    If using PHP you could try something like this:

    $value = '11';
    $first = '';
    $second = '';
    $third = '';
    $fourth = '';
    
    switch($value) {
                case '10' :
                    $first = 'selected';
                break;
                case '11' :
                    $second = 'selected';
                break;
                case '14' :
                    $third = 'selected';
                break;
                case '17' :
                    $fourth = 'selected';
                break;
            }
    
    echo'
    ';
    

提交回复
热议问题