[英]How to show and hide my contents when I click my icon
I just created a card-form(bootstrap) and in the form, there are a plus icon and hidden contents( id=mycontent_1 with display: none
).我刚刚创建了一个卡片表单(引导程序),在表单中,有一个加号图标和隐藏的内容( id=mycontent_1 with display: none
)。 what I'm trying to do is listed as follows.我正在尝试做的是如下所列。 I tried to do the first one on my java-script but it's not working.我试图在我的 java 脚本上做第一个,但它不起作用。
when I click plus icon, my function(toggler) should be executed and the icon would be hidden and my contents(text boxes and delete button) have to be visible.当我点击加号图标时,我的功能(切换器)应该被执行并且图标将被隐藏并且我的内容(文本框和删除按钮)必须是可见的。
similarly in opposite direction, when I click the delete button, my contents(text boxes and a delete button) have to be invisible and the plus icon should be visible.同样在相反的方向,当我单击删除按钮时,我的内容(文本框和删除按钮)必须不可见,加号图标应该可见。
need your kind helps for my two functions.我的两个功能需要您的帮助。 here are my codes for jsfiddle.这是我的 jsfiddle 代码。
https://jsfiddle.net/Sanchez/aq9Laaew/219304/ https://jsfiddle.net/Sanchez/aq9Laaew/219304/
<div class="col-sm-6">
<div class="card">
<div class="card-header" id="cardHeader1" style="visibility: hidden;"> no name </div>
<div class="card-body">
<a href="#" class="btn btn-info btn-lg" onclick="toggler('myContent_1');">
<span class="glyphicon glyphicon-plus" id=icon1 onclick="toggler('myContent_1');"></span> Plus
</a>
<div id="myContent_1" class="card-title" style="display: none;" >
<form action="" method="post">
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Number</span>
</div>
<input type="text" id="notiSeq_1" name="notiSeq" class="form-control" value="">
<div class="input-group-append">
<span class="input-group-text">
<i class="fa fa-sort-numeric-asc"></i>
</span>
</div>
</div>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Title</span>
</div>
<input type="text" id="title_1" name="title" class="form-control" value="">
<div class="input-group-append">
<span class="input-group-text">
<i class="fa fa-tumblr"></i>
</span>
</div>
</div>
</div>
<div class="form-group form-actions">
<button type="button" id="delBtn_1" class="btn btn-danger">Delete</button>
</div>
</form>
</div>
</div>
</div>
</div>
function toggler(divId){
var tempId = divId.slice(-1);
var x = document.getElementById("icon" + tempId);
var y = document.getElementById("cardHeader" + tempId);
x.style.display = "none";
y.style.visibility = "visible";
$("#delBtn_" + tempId).show();
$("#" + divId).toggle();
}
To begin with you should place you js code on the head before the body.首先,您应该将 js 代码放在身体之前的头部。 Afterwards, replace the a
tag with button
Finally call toggler
function on delete button's onclick之后,用button
替换a
标签最后在删除按钮的 onclick 上调用toggler
功能
<script>
function hidePlusBtn() {
$("#plusBtn").hide();
}
function toggler(divId) {
var tempId = divId.slice(-1);
var x = document.getElementById("icon" + tempId);
var y = document.getElementById("cardHeader" + tempId);
x.style.display = "none";
y.style.visibility = "visible";
$("#delBtn_" + tempId).show();
$("#" + divId).toggle();
}
</script>
<div class="col-sm-6">
...
<button
id="plusBtn"
class="btn btn-info btn-lg"
onclick="toggler('myContent_1');">
<span
class="glyphicon glyphicon-plus"
id=icon1
onclick="toggler('myContent_1');">
</span> Plus
</button>
...
<button
type="button"
id="delBtn_1"
class="btn btn-danger"
onclick="toggler('myContent_1'); hidePlusBtn()">Delete
</button>
...
</div>
Updated Demo: https://jsfiddle.net/1s390orm/更新演示: https : //jsfiddle.net/1s390orm/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.