jquery和js 判断下拉框选项选中值

时间:2023-03-08 17:54:46

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("")
}
});