// 默认选中第二个option
$("#ot_type")[0].selectedIndex = 1;
// 通过ot_type的值控制sp_type是否可用
$("#ot_type").change(function(){
if($(this).children('option:selected').val() == '' || $(this).children('option:selected').val() == '2'){
$("#sp_type").val('').attr("disabled","disabled");
}
if($(this).children('option:selected').val() == 1){
$("#sp_type").removeAttr("disabled");
}
});
本文介绍如何使用JavaScript实现网页中下拉框的默认选中项设置及通过一个下拉框的选择来控制另一个下拉框的可用状态。通过监听下拉框变化事件,动态调整目标下拉框的状态,实现页面元素间的交互与联动。
718

被折叠的 条评论
为什么被折叠?



