Home  >  Article  >  Web Front-end  >  How to hide div in jsp

How to hide div in jsp

anonymity
anonymityOriginal
2019-05-29 15:27:286263browse

In web pages, it is often necessary to use select controls to display and hide divs. The setAttribute method is mainly used to implement this method.

How to hide div in jsp

The following is sample code:

<html>
<title>通过选择项显示不同的结果</title>
<head>
<script type="text/JavaScript">
function showdiv()
{
var doc=document;
var citytext=doc.getElementById("city").value;
var div1=doc.getElementById("div1");
var div2=doc.getElementById("div2");
var div3=doc.getElementById("div3");
switch (citytext)
{
case "广州":    
    div1.setAttribute("style","display");
div2.setAttribute("style","display:none");
div3.setAttribute("style","display:none");
doc.getElementById("text1").value=citytext;
    break;
case "南昌":
    div1.setAttribute("style","display:none");
div2.setAttribute("style","display");
div3.setAttribute("style","display:none");
doc.getElementById("text2").value=citytext;
break;
case "沈阳":
    div1.setAttribute("style","display:none");
div2.setAttribute("style","display:none");
div3.setAttribute("style","display");
doc.getElementById("text3").value=citytext;
break;
}
}
</script>
</head>
<body>
<select title="城市" id="city" onchange="showdiv()">
<option selected value="广州">广州</option>
<option value="南昌">南昌</option>
<option value="沈阳">沈阳</option>
</select>
<div  id="div1" style="display:none"  >您选择了广东的省会<input type="text" id="text1" value=""/></div>
<div  id="div2" style="display:none"  >您选择了江西的省会<input type="text" id="text2" value=""/></div>
<div  id="div3" style="display:none"  >您选择了辽宁的省会<input type="text" id="text3" value=""/></div>
</body>
</html>

The above is the detailed content of How to hide div in jsp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What can jsp doNext article:What can jsp do