我有一个链式下拉框,同时警告第二个下拉框我在第一个盒子上发出警报

时间:2016-03-14 06:17:29

标签: javascript jquery html

从链式下拉框的第二个框中选择一个选项时,我需要收到警报,但在选择这两个框时我会收到警报。

<select id="test" name="test">
    <option value = ""> -- Select One -- </option>
    <option value = "a">car</option>
    <option value = "b">bike</option>
</select>
<select id="test3" name="test3" style="width:40%" onchange="alertInstitute(this)">
    <option value = "aa" class = "a">bmw</option>
    <option value = "ab" class = "a">audi</option>
    <option value = "ba" class = "b">harley davidson</option>
    <option value = "bb" class = "b">royal enfield</option>
</select>
<script>
    $jq("#test3").chained("#test");
    function alertInstitute(select){
        alert(select.options[select.selectedIndex].text);
    }
</script>

1 个答案:

答案 0 :(得分:3)

$(function () {
   $('#test3').change(function () {
      alert($('#test3 option:selected').text());
   });
});