[英]Replace show hide button with div
Javascript: Javascript:
<script>
function setVisibility(id) {
if (document.getElementById('bt1').value == 'Hide Layer') {
document.getElementById('bt1').value = 'Show Layer';
document.getElementById(id).style.display = 'none';
} else {
document.getElementById('bt1').value = 'Hide Layer';
document.getElementById(id).style.display = 'inline';
}
}
</script>
css 的CSS
div {
display: none;
}
HTML 的HTML
<input type=button name=type id='bt1' value='Show Layer' onClick="setVisibility('sub3');";>
<div id="sub3">Message Box</div>
This code works perfectly .. But when i click on the button it shows the message box along with the button 'Hide Layer' .. i want my message box to replace the button 'hide layer' n display in it's place.. 该代码可以正常工作..但是,当我单击按钮时,它显示消息框以及按钮“隐藏层” ..我希望消息框替换按钮“隐藏层”,而不是在其位置显示。
If you want to render message box only.Please refers following steps- 如果只想渲染消息框,请参考以下步骤:
step 1- Add following code into the HTML file 步骤1-将以下代码添加到HTML文件中
<input type=button name=type id='bt1' value='Show Layer' onClick="setVisibility('sub3');";>
<div id="sub3">Message Box</div>
<script>
function setVisibility(id) {
if (document.getElementById('bt1').value == 'Show Layer') {
document.getElementById(id).style.display = 'inline';
//above statement will show message box.
document.getElementById('bt1').style.display = 'none';
//above statement will hide 'Show layer' button.
}
}
</script>
step 2- add following code to the css 步骤2-将以下代码添加到CSS
div {
display: none;
}
To check example please refer this link- https://jsfiddle.net/yndyn8vj/ 要查看示例,请参考此链接-https : //jsfiddle.net/yndyn8vj/
You should do something like this. 你应该做这样的事情。
HTML 的HTML
<input type=button name=type id='bt1' value='Show Layer' onClick="setVisibility('sub3');";>
<div id="sub3" style="display:none">Message Box</div>
CSS - nothing CSS-没有
Javascript Java脚本
<script>
function setVisibility(id) {
var el = document.getElementById(id);
el.style.display = (el.style.display != 'none' ? 'none' : '');
}
</script>
Hope it helps. 希望能帮助到你。 Marco. 马可
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.