Skip to content

Commit f1c6aad

Browse files
committed
Translate Event: Browser-Event/Article.md - Handle
1 parent 6ca5e07 commit f1c6aad

File tree

1 file changed

+35
-35
lines changed
  • 2-ui/2-events/01-introduction-browser-events

1 file changed

+35
-35
lines changed

2-ui/2-events/01-introduction-browser-events/article.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,105 +26,105 @@ Berikut ini daftar peristiwa DOM yang paling berguna:
2626

2727
Masih banyak lagi peristiwa lain. Kita akan membahas lebih detail tentang peristiwa tertentu pada bab selanjutnya.
2828

29-
## Event handlers
29+
## Pengendali peristiwa (_Event handlers_)
3030

31-
To react on events we can assign a *handler* -- a function that runs in case of an event.
31+
Untuk menanggapi sebuah perristiwa kita dapat membuat pengendali -- sebuah fungsi yang akan dijalankan pada saat peristiwa itu terjadi.
3232

33-
Handlers are a way to run JavaScript code in case of user actions.
33+
Pengendali adalah sebuah cara untuk menjalankan kode Javascript pada saat pengguna melakukan sesuatu.
3434

35-
There are several ways to assign a handler. Let's see them, starting from the simplest one.
35+
Ada banyak cara untuk membuat sebuah handler. Mari kita pelajari, dimulai dari yang paling sederhana.
3636

37-
### HTML-attribute
37+
### Atribut HTML (_HTML-attribute_)
3838

39-
A handler can be set in HTML with an attribute named `on<event>`.
39+
Sebuah pengendali bisa di atur pada HTML dengan menggunakan atribute `on<event>`.
4040

41-
For instance, to assign a `click` handler for an `input`, we can use `onclick`, like here:
41+
Contohnya, untuk mengatur sebuah pengendali `klik` untuk `input`, kita bisa gunakan `onclick`, seperti ini:
4242

4343
```html run
44-
<input value="Click me" *!*onclick="alert('Click!')"*/!* type="button">
44+
<input value="Klik saya" *!*onclick="alert('Klik!')"*/!* type="button">
4545
```
4646

47-
On mouse click, the code inside `onclick` runs.
47+
Pada klik mouse, kode didalam `onclick` dijalankan.
4848

49-
Please note that inside `onclick` we use single quotes, because the attribute itself is in double quotes. If we forget that the code is inside the attribute and use double quotes inside, like this: `onclick="alert("Click!")"`, then it won't work right.
49+
Harap di catat bahwa didalam `onclick` kita gunakan tanda kutipan tunggal (_single quotes_), karena atribute itu sendiri menggunakan tanda kutip ganda (_double quotes_). Jika lupa bahwa kode tersebut didalam atribut dan menggunakan tanda kutip ganda (_double quotes_), seperti ini: `onclick="alert("Klik!")"`, maka itu tidak akan bekerja dengan benar.
5050

51-
An HTML-attribute is not a convenient place to write a lot of code, so we'd better create a JavaScript function and call it there.
51+
Sebuah atribute-HTML bukan tempat yang cocok untuk menulis banyak kode, jadi kita buat sebuah fungsi Javascript dan memanggilnya disana.
5252

53-
Here a click runs the function `countRabbits()`:
53+
Sebuah kilk menjalankan sebuah fungsi `hitungKelinci()`:
5454

5555
```html autorun height=50
5656
<script>
57-
function countRabbits() {
57+
function hitungKelinci() {
5858
for(let i=1; i<=3; i++) {
59-
alert("Rabbit number " + i);
59+
alert("Kelinci nomor " + i);
6060
}
6161
}
6262
</script>
6363

64-
<input type="button" *!*onclick="countRabbits()"*/!* value="Count rabbits!">
64+
<input type="button" *!*onclick="hitungKelinci()"*/!* value="Hitung Kelinci!">
6565
```
6666

67-
As we know, HTML attribute names are not case-sensitive, so `ONCLICK` works as well as `onClick` and `onCLICK`... But usually attributes are lowercased: `onclick`.
67+
Seperti yang kita ketahui, atribut HTML tidak _case-sensitive_, jadi `ONCLICK`, `onClick` dan `onCLICK` bisa digunakan... Tapi biasanya atribut menggunakan huruf kecil: `onclick`.
6868

69-
### DOM property
69+
### Properti DOM (_DOM property_)
7070

71-
We can assign a handler using a DOM property `on<event>`.
71+
Sebuah pengendali bisa di atur menggunakan properti DOM`on<event>`.
7272

73-
For instance, `elem.onclick`:
73+
Contohnya, `elem.onclick`:
7474

7575
```html autorun
76-
<input id="elem" type="button" value="Click me">
76+
<input id="elem" type="button" value="Klik saya">
7777
<script>
7878
*!*
7979
elem.onclick = function() {
80-
alert('Thank you');
80+
alert('Terima Kasih');
8181
};
8282
*/!*
8383
</script>
8484
```
8585

86-
If the handler is assigned using an HTML-attribute then the browser reads it, creates a new function from the attribute content and writes it to the DOM property.
86+
Jika pengendali di atur menggunakan atribut-HTML maka peramban membaca, membuat sebuah fungsi baru dari konten atribute dan menulisnya pada properti DOM.
8787

88-
So this way is actually the same as the previous one.
88+
Jadi cara ini sebenarnya sama dengan yang sebelumnya.
8989

90-
These two code pieces work the same:
90+
Kedua kode ini memiliki cara kerja yang sama:
9191

92-
1. Only HTML:
92+
1. Hanya HTML:
9393

9494
```html autorun height=50
95-
<input type="button" *!*onclick="alert('Click!')"*/!* value="Button">
95+
<input type="button" *!*onclick="alert('Klik!')"*/!* value="Tombol">
9696
```
9797
2. HTML + JS:
9898

9999
```html autorun height=50
100-
<input type="button" id="button" value="Button">
100+
<input type="button" id="button" value="Tombol">
101101
<script>
102102
*!*
103103
button.onclick = function() {
104-
alert('Click!');
104+
alert('Klik!');
105105
};
106106
*/!*
107107
</script>
108108
```
109109

110-
In the first example, the HTML attribute is used to initialize the `button.onclick`, while in the second example -- the script, that's all the difference.
110+
Pada contoh pertama, atribut HTML digunakan untuk menginisialisasikan `tombol.onclick`, sedangkan pada contoh kedua -- _script_, dan hanya itu perbedaanya.
111111

112-
**As there's only one `onclick` property, we can't assign more than one event handler.**
112+
**Karena hanya ada satu properti `onclick`, kita tidak bisa mengatur lebih dari satu pengendali peristiwa.**
113113

114-
In the example below adding a handler with JavaScript overwrites the existing handler:
114+
Pada contoh dibawah menambah sebuah pengendali menggunakan Javascript akan menimpa pengendali yang sudah ada:
115115

116116
```html run height=50 autorun
117-
<input type="button" id="elem" onclick="alert('Before')" value="Click me">
117+
<input type="button" id="elem" onclick="alert('Sebelum')" value="Klik saya">
118118
<script>
119119
*!*
120-
elem.onclick = function() { // overwrites the existing handler
121-
alert('After'); // only this will be shown
120+
elem.onclick = function() { // menimpa pengendali yang sudah ada
121+
alert('Sesudah'); // hanya ini yang akan ditunjukan
122122
};
123123
*/!*
124124
</script>
125125
```
126126

127-
To remove a handler -- assign `elem.onclick = null`.
127+
Untuk menghapus sebuah pengendali -- atur `elem.onclick = null`
128128

129129
## Accessing the element: this
130130

0 commit comments

Comments
 (0)