You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pada klik mouse, kode didalam `onclick`dijalankan.
48
48
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.
50
50
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.
52
52
53
-
Here a click runs the function `countRabbits()`:
53
+
Sebuah kilk menjalankan sebuah fungsi `hitungKelinci()`:
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`.
68
68
69
-
### DOM property
69
+
### Properti DOM (_DOM property_)
70
70
71
-
We can assign a handler using a DOM property `on<event>`.
71
+
Sebuah pengendali bisa di atur menggunakan properti DOM`on<event>`.
72
72
73
-
For instance, `elem.onclick`:
73
+
Contohnya, `elem.onclick`:
74
74
75
75
```html autorun
76
-
<inputid="elem"type="button"value="Click me">
76
+
<inputid="elem"type="button"value="Klik saya">
77
77
<script>
78
78
*!*
79
79
elem.onclick=function() {
80
-
alert('Thank you');
80
+
alert('Terima Kasih');
81
81
};
82
82
*/!*
83
83
</script>
84
84
```
85
85
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.
87
87
88
-
So this way is actually the same as the previous one.
88
+
Jadi cara ini sebenarnya sama dengan yang sebelumnya.
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.
111
111
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.**
113
113
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:
0 commit comments