Py学习  »  Jquery

使用不带jquery的javascript从多个不同的选定下拉列表项中获取值

Sed Ward • 5 年前 • 1224 次点击  

我希望能够从两个不同的下拉列表中选择多个值,并使用输出值调用单独的函数。我可以独立获取每个值,但希望能够有一个同时获取这两个值的函数

<!DOCTYPE html>
<html>
<body>

<select id ="cars1">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

  <select id ="cars2">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

<script>

//select the value from the dropdown table with id ="cars1"
            var selectCars1 = document.getElementById("cars1");
            selectCars1.onchange = function start(){

                var Cars1Value = selectCars1.options[selectCars1.selectedIndex].value;
                 alert(Cars1Value);

            }

       //select the value from the dropdown table with id ="cars2"

            var selectCars2 = document.getElementById("cars2");
            selectCars2.onchange = function(){
                var Cars2Value = selectCars2.options[selectCars2.selectedIndex].value;
                alert(Cars2Value);

            }

  </script>

</body>
</html>
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/48488
 
1224 次点击  
文章 [ 1 ]  |  最新文章 5 年前