选择选项,并使用html

时间:2018-09-30 17:15:06

标签: javascript jquery html css

我想选择一个选项,并在另一个带有值的选择中获得结果

<script type="text/javascript">
     function configureDropDownLists(ddl1,ddl2) {
    var names = ['john', 'jane', 'mike'];
    var birth = ['25', '26', '27'];
    var animal = ['fish', 'goat', 'cow'];

    switch (ddl1.value) {
        case 'names':
            ddl2.options.length = 0;
            for (i = 0; i < names.length; i++) {
                createOption(ddl2, names[i], names[i]);
            }
            break;
        case 'birth':
            ddl2.options.length = 0; 
        for (i = 0; i < birth.length; i++) {
            createOption(ddl2, birth[i], birth[i]);
            }
            break;
        case 'animal':
            ddl2.options.length = 0;
            for (i = 0; i < animal.length; i++) {
                createOption(ddl2, animal[i], animal[i]);
            }
            break;
            default:
                ddl2.options.length = 0;
            break;
    }

}

    function createOption(ddl, text, value) {
        var opt = document.createElement('option');
        opt.value = value;
        opt.text = text;
        ddl.options.add(opt);
    }
</script>

<select id="ddl" onchange="configureDropDownLists(this,document.getElementById('ddl2'))">
<option value=""></option>
<option value="names">names</option>
<option value="birth">birth</option>
<option value="animal">animal</option>
</select>

<select id="ddl2">
<option value="#getvalue">#john,jane or mike</option>
<option value="getvalue">#25,26 or 27</option>
<option value="getvalue">#fish, goat or cow</option>
</select>

所以我想用那里的值设置var。因此,如果我选择,我将获得带有值的结果 如果有什么办法,我可以在var之类。我感谢您的建议和示例

var names = ['john',value ='',  'jane', value ='', 'mike' value ='', ];
    var birth = ['25', value ='', '26', value ='', '27' value ='', ];
    var animal = ['fish', value ='',  'goat',value ='',  'cow' value ='', ];

所以我想获取值和结果

0 个答案:

没有答案