|
167 | 167 | <!-- را اضافه کنید class -- روی فرم focus در مورد --> |
168 | 168 |
|
169 | 169 | <form *!*onfocus="this.className='focused'"*/!*> |
170 | | - <input type="text" name="name" value="Name"> |
171 | | - <input type="text" name="surname" value="Surname"> |
| 170 | + <input type="text" name="name" value="نام"> |
| 171 | + <input type="text" name="surname" value="نام خانوادگی"> |
172 | 172 | </form> |
173 | 173 |
|
174 | 174 | <style> .focused { outline: 1px solid red; } </style> |
175 | 175 | ``` |
176 | 176 |
|
177 | | -The example above doesn't work, because when user focuses on an `<input>`, the `focus` event triggers on that input only. It doesn't bubble up. So `form.onfocus` never triggers. |
| 177 | +مثال بالا کار نمیکند زیرا وقتی کاربر روی یک `<input>` فوکوس میکند، `focus` event فقط روی آن input فعال میشود. رفتار بالا رفتن حبابی ندارد. پس `form.onfocus` هیچوقت فعال نمیشود. |
| 178 | + |
| 179 | +دو راه حل وجود دارد. |
178 | 180 |
|
179 | | -There are two solutions. |
| 181 | +ابندا یک ویژگی قدیمی خندهدار وجود دارد: `focus/blur` بالا رفتن حبابی ندارند، بلکه در مرحلهی capturing به پایین منتشر میشوند. |
180 | 182 |
|
181 | | -First, there's a funny historical feature: `focus/blur` do not bubble up, but propagate down on the capturing phase. |
182 | 183 |
|
183 | | -This will work: |
| 184 | +این کار میکند: |
184 | 185 |
|
185 | 186 | ```html autorun height=80 |
186 | 187 | <form id="form"> |
187 | | - <input type="text" name="name" value="Name"> |
188 | | - <input type="text" name="surname" value="Surname"> |
| 188 | + <input type="text" name="name" value="نام"> |
| 189 | + <input type="text" name="surname" value="نام خانوادگی"> |
189 | 190 | </form> |
190 | 191 |
|
191 | 192 | <style> .focused { outline: 1px solid red; } </style> |
192 | 193 |
|
193 | 194 | <script> |
194 | 195 | *!* |
195 | | - // put the handler on capturing phase (last argument true) |
| 196 | + //قرار دهید (آخرین آرگومان درست) capturing کنترلگر را روی فاز |
196 | 197 | form.addEventListener("focus", () => form.classList.add('focused'), true); |
197 | 198 | form.addEventListener("blur", () => form.classList.remove('focused'), true); |
198 | 199 | */!* |
|
0 commit comments