<td> <input type="radio" class="radio" id="unitChaDian-1" name="unitChaDian" value="2" onclick="unitTypeChange(this.value)"/> <label for="unitChaDian-1" class="hand">委办局</label> <input type="radio" id="unitChaDian-2" name="unitChaDian" value="5" onclick="unitTypeChange(this.value)"/> <label for="unitChaDian-2" class="hand">镇街</label> <div class="selectTree validate[required]" name="receiveUnit" id="receiveUnit" selectedValue="${inspect.receiveUnit}" > </div> <div class="selectTree validate[required]" name="receiveStreet" id="receiveStreet" selectedValue="${inspect.receiveUnit}" > </div> </td>//首报区应急办单位 function unitTypeChange(value){ if(value) {//选中事件 let receiveUnit = ""; var url="${ctx}/system/dept/getTreeSelect?deptPlies=1&nameType=1&deptType="+value; $.post(url,function(result){ $("#receiveUnit").attr("selectedValue",receiveUnit); //赋给data $("#receiveUnit").data("data",result) //刷新下拉框 $("#receiveUnit").render(); },"json"); $("#receiveUnit").css("display","inherit"); }以上代码中我要判断选的是委办局还是街镇如果我选委办局就把镇街的下拉框隐藏并且置空怎么写
时间: 2023-07-03 21:25:13 浏览: 90
你可以在 `unitTypeChange` 函数中加入以下代码:
```
function unitTypeChange(value) {
if (value) {
// 选中委办局
if (value === "2") {
// 隐藏街镇下拉框
$("#receiveStreet").hide();
// 置空街镇下拉框
$("#receiveStreet").empty();
}
// 选中镇街
else if (value === "5") {
// 显示街镇下拉框
$("#receiveStreet").show();
// 置空委办局下拉框
$("#receiveUnit").empty();
}
let receiveUnit = "";
var url = "${ctx}/system/dept/getTreeSelect?deptPlies=1&nameType=1&deptType=" + value;
$.post(url, function(result) {
$("#receiveUnit").attr("selectedValue", receiveUnit);
// 赋给data
$("#receiveUnit").data("data", result);
// 刷新下拉框
$("#receiveUnit").render();
}, "json");
$("#receiveUnit").css("display", "inherit");
}
}
```
其中,当选中委办局时,我们通过 `$("#receiveStreet").hide();` 隐藏街镇下拉框,再通过 `$("#receiveStreet").empty();` 置空街镇下拉框;当选中镇街时,我们通过 `$("#receiveStreet").show();` 显示街镇下拉框,再通过 `$("#receiveUnit").empty();` 置空委办局下拉框。
阅读全文