我有一个正常工作的切换按钮,我只想创建一个只与切换相互作用的按钮,当我点击按钮时,切换将继续,当我再次点击按钮时,切换将关闭
Toggle.html
<ion-toggle class="toggle-small" toggle-class="toggle-calm" id="toggle" (ionChange)="add(ioToggle.checked)" #ioToggle ></ion-toggle>
有办法吗?
答案 0 :(得分:1)
首先添加[(ngModel)]="status"
<ion-toggle [(ngModel)]="status" class="toggle-small" toggle-class="toggle-calm" id="toggle" (ionChange)="add(ioToggle.checked)" #ioToggle ></ion-toggle>
然后添加一个按钮:
<!-- Bind the click event to a method -->
<button ion-button (click)="buttonClick($event)">
Click me!
</button>
.ts
中的:
首先在类的开头定义status
,然后定义buttonClick
函数:
...
status = false;
...
buttonClick(event) {
this.status = !this.status
}
答案 1 :(得分:0)
function switchx(){
var x = document.getElementById('input1')
x.checked = !x.checked}
/*the stopit function prevents being able to click on the switch */
function stopit(){
var x = document.getElementById('input1')
x.checked = !x.checked
}
&#13;
#button2{
display:none;
}
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {display:none;}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
&#13;
<h2>Toggle Switch</h2>
<label class="switch">
<input id='input1' type="checkbox" onclick='stopit()'>
<span class="slider"></span>
</label>
<button id='button1' onclick='switchx()'>switch</button>
&#13;