xxxxxxxxxx
1
<!-- Button trigger modal -->
2
<button type="button" class="btn btn-primary" data-mdb-ripple-init data-mdb-modal-init data-mdb-target="#exampleModal">
3
Launch demo modal
4
</button>
5
6
<!-- Modal -->
7
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
8
<div class="modal-dialog">
9
<div class="modal-content">
10
<div class="modal-header">
11
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
12
<button type="button" class="btn-close" data-mdb-ripple-init data-mdb-dismiss="modal" aria-label="Close"></button>
13
</div>
14
<div class="modal-body">
15
<div class="form-outline" data-mdb-input-init>
16
<input type="text" id="copy-target-4" class="form-control" />
17
<label class="form-label" for="copy-target-4">Type here text to copy</label>
18
</div>
19
<button id="myExample" class="btn btn-primary" data-mdb-clipboard-init data-mdb-clipboard-target="#copy-target-4" data-mdb-ripple-init>
20
Copy
21
</button>
22
</div>
23
<div class="modal-footer">
24
<button type="button" class="btn btn-secondary" data-mdb-ripple-init data-mdb-dismiss="modal">Close</button>
25
<button type="button" class="btn btn-primary" data-mdb-ripple-init>Save changes</button>
26
</div>
27
</div>
28
</div>
29
</div>
30
31
32
<div
33
class="alert fade mt-5"
34
id="container-example"
35
role="alert"
36
data-mdb-alert-init
37
data-mdb-color="primary"
38
data-mdb-hidden="true"
39
data-mdb-autohide="true"
40
data-mdb-delay="4000"
41
data-mdb-position="top-right"
42
data-mdb-width="25%"
43
>
44
Text copied!
45
</div>
1
1
xxxxxxxxxx
1
const myExample = document.querySelector('#myExample');
2
const alertInstance = mdb.Alert.getInstance(document.querySelector('#container-example'));
3
4
5
myExample.addEventListener('copied.mdb.clipboard', ()=> {
6
myExample.innerText = 'COPIED!'
7
alertInstance.show()
8
setTimeout(() => {
9
myExample.innerText = 'COPY'
10
}, 4000);
11
})
Console errors: 0