Skip to content

Commit 3b0be51

Browse files
yourankimViolet-Bora-Lee
authored andcommitted
[폼 프로퍼티와 메서드] 본문 번역
1 parent d56e316 commit 3b0be51

File tree

1 file changed

+89
-89
lines changed

1 file changed

+89
-89
lines changed
Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# Form properties and methods
1+
# 폼 프로퍼티와 메서드
22

3-
Forms and control elements, such as `<input>` have a lot of special properties and events.
3+
`<input>`과 같이 폼(form) 조작에 사용되는 요소에는 특별한 프로퍼티와 이벤트가 많습니다.
44

5-
Working with forms will be much more convenient when we learn them.
5+
이 프로퍼티와 이벤트들을 익히고 나면 폼을 다루기가 훨씬 편리해질 겁니다.
66

7-
## Navigation: form and elements
7+
## 폼과 요소 탐색하기
88

9-
Document forms are members of the special collection `document.forms`.
9+
폼은 특수한 컬렉션인 `document.forms`의 구성원입니다.
1010

11-
That's a so-called "named collection": it's both named and ordered. We can use both the name or the number in the document to get the form.
11+
`document.forms`는 이름과 순서가 있는 '기명 컬렉션(named collection)'입니다. 개발자는 이 이름이나 순서를 사용해 문서 내의 폼에 접근할 수 있습니다.
1212

1313
```js no-beautify
14-
document.forms.my - the form with name="my"
15-
document.forms[0] - the first form in the document
14+
document.forms.my - 이름이 'my'인 폼
15+
document.forms[0] - 문서 내의 첫 번째 폼
1616
```
1717

18-
When we have a form, then any element is available in the named collection `form.elements`.
18+
이름이나 순서를 사용해 원하는 폼을 가져온 다음에는 기명 컬렉션 `form.elements`를 사용해 폼의 요소를 얻을 수 있습니다.
1919

20-
For instance:
20+
예시:
2121

2222
```html run height=40
2323
<form name="my">
@@ -26,19 +26,19 @@ For instance:
2626
</form>
2727

2828
<script>
29-
// get the form
30-
let form = document.forms.my; // <form name="my"> element
29+
// 폼 얻기
30+
let form = document.forms.my; // <form name="my"> 요소
3131
32-
// get the element
33-
let elem = form.elements.one; // <input name="one"> element
32+
// 요소 얻기
33+
let elem = form.elements.one; // <input name="one"> 요소
3434
3535
alert(elem.value); // 1
3636
</script>
3737
```
3838

39-
There may be multiple elements with the same name, that's often the case with radio buttons.
39+
그런데 개발을 하다 보면 이름이 같은 요소 여러 개를 다뤄야 하는 경우가 생기기도 합니다. 라디오 버튼을 다룰 때 이런 상황이 자주 발생하죠.
4040

41-
In that case `form.elements[name]` is a collection, for instance:
41+
이때 `form.elements[name]`은 컬렉션이 된다는 사실을 이용할 수 있습니다. 예시를 살펴봅시다.
4242

4343
```html run height=40
4444
<form>
@@ -57,13 +57,13 @@ alert(ageElems[0]); // [object HTMLInputElement]
5757
</script>
5858
```
5959

60-
These navigation properties do not depend on the tag structure. All control elements, no matter how deep they are in the form, are available in `form.elements`.
60+
폼 요소 탐색에 쓰이는 프로퍼티는 태그 구조에 의존하지 않습니다. 폼을 조작하는 데 쓰이는 요소들은 모두 태그 깊이에 상관없이 `form.elements`을 사용해 접근할 수 있습니다.
6161

6262

63-
````smart header="Fieldsets as \"subforms\""
64-
A form may have one or many `<fieldset>` elements inside it. They also have `elements` property that lists form controls inside them.
63+
````smart header="\'하위 폼\'처럼 쓰이는 fieldset"
64+
폼은 하나 이상의 `<fieldset>` 요소를 포함할 수 있습니다. 폼 내부에 있는 fieldset도 폼과 마찬가지로 자신의 내부에 있는 폼 조작 요소에 접근할 수 있도록 해주는 `elements` 프로퍼티를 지원합니다.
6565
66-
For instance:
66+
예시:
6767
6868
```html run height=80
6969
<body>
@@ -81,57 +81,57 @@ For instance:
8181
let fieldset = form.elements.userFields;
8282
alert(fieldset); // HTMLFieldSetElement
8383
84-
// we can get the input by name both from the form and from the fieldset
84+
// 이름을 사용해 form과 fieldset 모두에서 input을 구할 수 있습니다.
8585
alert(fieldset.elements.login == form.elements.login); // true
8686
*/!*
8787
</script>
8888
</body>
8989
```
9090
````
9191

92-
````warn header="Shorter notation: `form.name`"
93-
There's a shorter notation: we can access the element as `form[index/name]`.
92+
````warn header="짧은 표기법: `form.name`"
93+
짧은 표기법인 `form[index/name]`으로도 요소에 접근할 수 있습니다.
9494

95-
In other words, instead of `form.elements.login` we can write `form.login`.
95+
`form.elements.login` 대신 `form.login`처럼 쓸 수 있죠.
9696

97-
That also works, but there's a minor issue: if we access an element, and then change its `name`, then it is still available under the old name (as well as under the new one).
97+
`form.name`을 사용한 표기법은 잘 작동하긴 하지만 요소에 접근해 `name` 속성을 변경해도 변경 전 이름을 계속 사용할 수 있다는 문제가 있습니다(물론 새로운 이름도 사용할 수 있습니다).
9898

99-
That's easy to see in an example:
99+
예시를 통해 확인해 봅시다.
100100

101101
```html run height=40
102102
<form id="form">
103103
<input name="login">
104104
</form>
105105

106106
<script>
107-
alert(form.elements.login == form.login); // true, the same <input>
107+
alert(form.elements.login == form.login); // true, 동일한 <input>입니다.
108108
109-
form.login.name = "username"; // change the name of the input
109+
form.login.name = "username"; // input의 name 속성을 변경합니다.
110110
111-
// form.elements updated the name:
111+
// form.elements에는 name 속성 변경이 반영되었습니다.
112112
alert(form.elements.login); // undefined
113113
alert(form.elements.username); // input
114114
115115
*!*
116-
// form allows both names: the new one and the old one
116+
// form은 새로운 이름과 이전 이름을 모두 인식합니다.
117117
alert(form.username == form.login); // true
118118
*/!*
119119
</script>
120120
```
121121

122-
That's usually not a problem, because we rarely change names of form elements.
122+
그런데 폼 요소의 이름을 변경하는 일은 드물기 때문에 보통은 이런 특징이 문제가 되지 않습니다.
123123

124124
````
125125
126-
## Backreference: element.form
126+
## element.form으로 역참조 하기
127127
128-
For any element, the form is available as `element.form`. So a form references all elements, and elements reference the form.
128+
모든 요소는 `element.form`으로 폼에 접근할 수 있습니다. 폼이 내부에 있는 요소 모두를 참조할 수 있듯이 각 요소 또한 역으로 폼을 참조할 수 있죠.
129129
130-
Here's the picture:
130+
그림으로 나타내면 다음과 같습니다.
131131
132132
![](form-navigation.svg)
133133
134-
For instance:
134+
예시:
135135
136136
```html run height=40
137137
<form id="form">
@@ -140,55 +140,55 @@ For instance:
140140
141141
<script>
142142
*!*
143-
// form -> element
143+
// -> 요소
144144
let login = form.login;
145145
146-
// element -> form
146+
// 요소 ->
147147
alert(login.form); // HTMLFormElement
148148
*/!*
149149
</script>
150150
```
151151
152-
## Form elements
152+
## 폼 요소
153153
154-
Let's talk about form controls.
154+
이제 폼 조작에 사용되는 요소들에 대해 살펴봅시다.
155155
156-
### input and textarea
156+
### input과 textarea
157157
158-
We can access their value as `input.value` (string) or `input.checked` (boolean) for checkboxes.
158+
input과 textarea 요소의 값은 `input.value` (string) 또는 `input.checked`(boolean)을 사용해 얻을 수 있습니다.
159159
160-
Like this:
160+
이렇게 말이죠.
161161
162162
```js
163163
input.value = "New value";
164164
textarea.value = "New text";
165165
166-
input.checked = true; // for a checkbox or radio button
166+
input.checked = true; // 체크박스나 라디오 버튼에서 쓸 수 있습니다.
167167
```
168168
169-
```warn header="Use `textarea.value`, not `textarea.innerHTML`"
170-
Please note that even though `<textarea>...</textarea>` holds its value as nested HTML, we should never use `textarea.innerHTML` to access it.
169+
```warn header="`textarea.innerHTML` 말고 `textarea.value`를 사용하세요."
170+
`<textarea>...</textarea>`안의 값이 HTML이더라도 값을 얻을 때 `textarea.innerHTML`을 사용하지 말아야 합니다.
171171
172-
It stores only the HTML that was initially on the page, not the current value.
172+
`textarea.innerHTML`엔 페이지를 처음 열 당시의 HTML만 저장되어 최신 값을 구할 수 없기 때문입니다.
173173
```
174174
175-
### select and option
175+
### select와 option
176176
177-
A `<select>` element has 3 important properties:
177+
`<select>` 요소에는 세 가지 중요 프로퍼티가 있습니다.
178178
179-
1. `select.options` -- the collection of `<option>` subelements,
180-
2. `select.value` -- the value of the currently selected `<option>`,
181-
3. `select.selectedIndex` -- the number of the currently selected `<option>`.
179+
1. `select.options` -- `<option>` 하위 요소를 담고 있는 컬렉션
180+
2. `select.value` -- 현재 선택된 `<option>`
181+
3. `select.selectedIndex` -- 현재 선택된 `<option>`의 번호(인덱스)
182182
183-
They provide three different ways of setting a value for a `<select>`:
183+
이 세 프로퍼티를 응용하면 아래와 같은 세 가지 방법으로 `<select>`의 값을 설정할 수 있습니다.
184184
185-
1. Find the corresponding `<option>` element and set `option.selected` to `true`.
186-
2. Set `select.value` to the value.
187-
3. Set `select.selectedIndex` to the number of the option.
185+
1. 조건에 맞는 `<option>` 하위 요소를 찾아 `option.selected`속성을 `true`로 설정합니다.
186+
2. `select.value`를 원하는 값으로 설정합니다.
187+
3. `select.selectedIndex`를 원하는 option 번호로 설정합니다.
188188
189-
The first way is the most obvious, but `(2)` and `(3)` are usually more convenient.
189+
세 방법 중 첫 번째 방법이 가장 확실하지만 두 번째나 세 번째 방법이 대체로 더 편리합니다.
190190
191-
Here is an example:
191+
예시:
192192
193193
```html run
194194
<select id="select">
@@ -198,16 +198,16 @@ Here is an example:
198198
</select>
199199
200200
<script>
201-
// all three lines do the same thing
201+
// 세 가지 코드의 실행 결과는 모두 같습니다.
202202
select.options[2].selected = true;
203203
select.selectedIndex = 2;
204204
select.value = 'banana';
205205
</script>
206206
```
207207
208-
Unlike most other controls, `<select>` allows to select multiple options at once if it has `multiple` attribute. That's feature is rarely used. In that case we need to use the first way: add/remove the `selected` property from `<option>` subelements.
208+
대부분의 다른 폼 조작 요소와 달리 `<select>`는 `multiple` 속성이 있는 경우 option을 다중 선택할 수 있습니다. `multiple` 속성을 쓰는 경우는 아주 드물지만, 쓰게 되다면 첫 번째 방법을 사용해 `<option>` 하위 요소에 있는 `selected` 프로퍼티를 추가·제거해야 합니다.
209209
210-
We can get their collection as `select.options`, for instance:
210+
선택된 여러 개의 option이 담긴 컬렉션은 다음 예시처럼 `select.options`를 사용해 얻을 수 있습니다.
211211
212212
```html run
213213
<select id="select" *!*multiple*/!*>
@@ -217,7 +217,7 @@ We can get their collection as `select.options`, for instance:
217217
</select>
218218
219219
<script>
220-
// get all selected values from multi-select
220+
// 선택한 값 전체
221221
let selected = Array.from(select.options)
222222
.filter(option => option.selected)
223223
.map(option => option.value);
@@ -226,72 +226,72 @@ We can get their collection as `select.options`, for instance:
226226
</script>
227227
```
228228
229-
The full specification of the `<select>` element is available in the specification <https://html.spec.whatwg.org/multipage/forms.html#the-select-element>.
229+
`<select>` 요소에 대한 명세는 아래 링크에서 볼 수 있습니다 <https://html.spec.whatwg.org/multipage/forms.html#the-select-element>.
230230
231-
### new Option
231+
### Option 생성자
232232
233-
This is rarely used on its own. But there's still an interesting thing.
233+
Option 생성자는 잘 사용되지는 않지만 흥미로운 점이 있습니다.
234234
235-
In the [specification](https://html.spec.whatwg.org/multipage/forms.html#the-option-element) there's a nice short syntax to create `<option>` elements:
235+
[명세서](https://html.spec.whatwg.org/multipage/forms.html#the-option-element)를 보면 `<option>` 요소를 생성하는 간단하고 멋진 문법을 찾을 수 있죠.
236236
237237
```js
238238
option = new Option(text, value, defaultSelected, selected);
239239
```
240240
241-
Parameters:
241+
매개변수:
242242
243-
- `text` -- the text inside the option,
244-
- `value` -- the option value,
245-
- `defaultSelected` -- if `true`, then `selected` HTML-attribute is created,
246-
- `selected` -- if `true`, then the option is selected.
243+
- `text` -- option 내부의 텍스트
244+
- `value` -- option의 값
245+
- `defaultSelected` -- `true`이면 HTML 속성 `selected`가 생성됨
246+
- `selected` -- `true`이면 해당 option이 선택됨
247247
248-
There may be a small confusion about `defaultSelected` and `selected`. That's simple: `defaultSelected` sets HTML-attribute, that we can get using `option.getAttribute('selected')`. And `selected` - whether the option is selected or not, that's more important. Usually both values are either set to `true` or not set (same as `false`).
248+
`defaultSelected``selected`의 차이가 무엇인지 헷갈릴 수 있습니다. `defaultSelected``option.getAttribute('selected')`를 사용해 얻을 수 있는 HTML 속성을 설정해 줍니다. 반면 `selected` 는 option의 선택 여부를 결정합니다. 그렇기 때문에 당연히 `selected`가 더 중요한 매개변수이죠. Option 생성자를 사용할 때는 대개 두 매개변수 모두를 `true``false`로 설정합니다.
249249
250-
For instance:
250+
예시:
251251
252252
```js
253253
let option = new Option("Text", "value");
254-
// creates <option value="value">Text</option>
254+
// <option value="value">Text</option> 가 생성됩니다.
255255
```
256256
257-
The same element selected:
257+
이번엔 같은 요소를 선택된 상태로 생성합니다.
258258
259259
```js
260260
let option = new Option("Text", "value", true, true);
261261
```
262262
263-
Option elements have properties:
263+
Option을 사용해 만든 요소에는 다음과 같은 프로퍼티가 있습니다.
264264
265265
`option.selected`
266-
: Is the option selected.
266+
: option의 선택 여부
267267
268268
`option.index`
269-
: The number of the option among the others in its `<select>`.
269+
: option 중 몇 번째인지를 나타내는 번호
270270
271271
`option.text`
272-
: Text content of the option (seen by the visitor).
272+
: 사용자가 보게 될 텍스트
273273
274-
## References
274+
## 참고 자료
275275
276-
- Specification: <https://html.spec.whatwg.org/multipage/forms.html>.
276+
- 명세서: <https://html.spec.whatwg.org/multipage/forms.html>.
277277
278-
## Summary
278+
## 요약
279279
280-
Form navigation:
280+
폼 탐색하기
281281
282282
`document.forms`
283-
: A form is available as `document.forms[name/index]`.
283+
: `document.forms[name/index]`로 폼에 접근할 수 있습니다.
284284
285285
`form.elements`
286-
: Form elements are available as `form.elements[name/index]`, or can use just `form[name/index]`. The `elements` property also works for `<fieldset>`.
286+
: 폼 요소는 `form.elements[name/index]` 또는 `form[name/index]`로 접근합니다. `elements` 프로퍼티는 `<fieldset>`에도 똑같이 작동합니다.
287287
288288
`element.form`
289-
: Elements reference their form in the `form` property.
289+
: 요소는 `form` 프로퍼티에서 자신이 속한 폼을 참조합니다.
290290
291-
Value is available as `input.value`, `textarea.value`, `select.value` etc, or `input.checked` for checkboxes and radio buttons.
291+
각 요소의 값은 `input.value`, `textarea.value`, `select.value` 등으로 접근할 수 있습니다. 체크박스와 라디오 버튼에서는 `input.checked`를 사용할 수 있습니다.
292292
293-
For `<select>` we can also get the value by the index `select.selectedIndex` or through the options collection `select.options`.
293+
`<select>`에서는 인덱스 `select.selectedIndex`나 option 컬렉션 `select.options`을 통해 값을 구할 수도 있습니다.
294294
295-
These are the basics to start working with forms. We'll meet many examples further in the tutorial.
295+
지금까지는 폼을 다루기 위한 기초적인 내용이었습니다. 이 튜토리얼에서 앞으로 더 많은 예시를 만날 것입니다.
296296
297-
In the next chapter we'll cover `focus` and `blur` events that may occur on any element, but are mostly handled on forms.
297+
다음 챕터에서는 어느 요소에서든 발생할 수 있지만 대부분 폼에서 처리되는 `focus``blur` 이벤트를 다루겠습니다.

0 commit comments

Comments
 (0)