JS显示隐藏节点

<tr>
  <td class="emBold"><font color="#FF0000">*</font> State:</td>
  

  <td>
    <asp:DropDownList ID="ddlState" runat="server" onchange="CheckState()"/>
    <asp:RequiredFieldValidator ID="rfvState" runat="server" ErrorMessage="The State is required" ControlToValidate="ddlState"/>
  </td>
</tr>

//ID为"rfvState"的父节点的上一个兄弟节点的第一个子节点,即红色星号*显示

document.getElementById("rfvState").parentElement.previousElementSibling.firstChild.style.visibility = "visible";

//ID为"rfvState"的父节点的上一个兄弟节点的第一个子节点,即红色星号*隐藏
document.getElementById("rfvState").parentElement.previousElementSibling.firstChild.style.visibility = "hidden";

document.getElementById("rfvState").parentElement.previousElementSibling.firstChild.style.display = "block";

document.getElementById("rfvState").parentElement.previousElementSibling.firstChild.style.display = "inline-block";

//将<font>节点样式全部隐藏,即红色星号*和占位的空白都删除,State会最靠左顶格显示

document.getElementById("rfvState").parentElement.previousElementSibling.firstChild.style.display = "none";

var St = "";
function CheckState() {
St = document.getElementById("ddlState").value;
}

function CheckCountry() {
if (document.getElementById("ddlCountry").value == "USA") {
document.getElementById("ddlState").value = St;
PackageinfoValidatorsStAndZip(true);
document.getElementById("rfvState").parentElement.previousElementSibling.firstChild.style.visibility = "visible";
document.getElementById("rfvZipCode").parentElement.previousElementSibling.firstChild.style.visibility = "visible";
} else {
document.getElementById("ddlState").value = "";
PackageinfoValidatorsStAndZip(false);
document.getElementById("rfvState").parentElement.previousElementSibling.firstChild.style.visibility = "hidden";
document.getElementById("rfvZipCode").parentElement.previousElementSibling.firstChild.style.visibility = "hidden";
}

原文地址:https://www.cnblogs.com/HuairongChen/p/13403158.html