js如何实现控制p标签的显示和隐藏
参考:https://jingyan.baidu.com/article/e8cdb32b732ab676052bada7.html
js实现点击标签显示和隐藏p标签
代码如下
<html>
<head>
<meta charset='utf-8'>
</head>
<body>
<p id='targetp' > 这是一行测试文字</p>
<button onclick=showp('targetp') >显示</button>
<button onclick=hidep('targetp') >隐藏</button>
<script>
function showp(id){
document.getElementById(id).style.display='inline';
}
function hidep(id){
document.getElementById(id).style.display='none';
}
</script>
</body>
</html>
解析:定义两个函数一个为显示函数showp一个为隐藏函数hidep函数传递的参数为对象的id,当点击对应按钮时触发事件,事件分别为隐藏和显示对应的对象,本次对象为一个p标签
页面效果如下




浙公网安备 33010602011771号