1. 程式人生 > >jquery和js 判斷下拉框選項選中值

jquery和js 判斷下拉框選項選中值

變異 scrip select his () pre variant color span

js

<script>
    var selectId = document.getElementById("VariantType");//獲取ID
    selectId.onchange = function ()
    {
        var result = selectId.options[selectId.selectedIndex].innerHTML;//獲取選中文本
        if (result == "Fusion") {  //當變異類型的值為Fusion時,變異值為空
            $("#Variant").val("");
        }
    }
</script>

jquery

$("#VariantType").change(function () {
            var result = $(this).children(‘option:selected‘).val();
            if (result  == "Fusion") {
                $("#Variant").val("")
            } 
});

jquery和js 判斷下拉框選項選中值