Home > Article > Web Front-end > How to implement JS click link to switch to display hidden content
This article mainly introduces the JS method of switching to display hidden content by clicking on a link, involving javascript mouse event response and dynamic transformation of page element attributes related operating techniques. Friends in need can refer to the following
Examples of this article Use JS to implement the method of clicking on a link to switch to displaying hidden content. Share it with everyone for your reference, the details are as follows:
Let’s take a look at the running effect first:
The specific code is as follows:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.jb51.net 点击链接切换显示隐藏内容</title> <style> a { cursor: pointer; color: red; } #p1, #p2 { display: none; } </style> </head> <body> <a onclick="con(1)">显示内容1</a> <a onclick="con(2)">显示内容2</a> <p id="p1">11111</p> <p id="p2">22222</p> <script> flag = "p1"; function con(i){ //参数传递时传递字符串似乎有问题,这里采用的是数字传参 document.getElementById(flag).style.display = "none"; document.getElementById("p" + i).style.display = "inline"; flag = "p" + i; } </script> </body> </html>
The above is the detailed content of How to implement JS click link to switch to display hidden content. For more information, please follow other related articles on the PHP Chinese website!