الفرق بين المراجعتين ل"JavaScript/Document/forms"
< JavaScript | Document
اذهب إلى التنقل
اذهب إلى البحث
ط |
(←أمثلة: تعديل الأمثلة) |
||
سطر 16: | سطر 16: | ||
==أمثلة== | ==أمثلة== | ||
الحصول على معلومات نموذج مُعيّن: | الحصول على معلومات نموذج مُعيّن: | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="html"> |
<!DOCTYPE html> | <!DOCTYPE html> | ||
<html lang="en"> | <html lang="en"> | ||
+ | <head> | ||
+ | <title>document.forms</title> | ||
+ | </head> | ||
+ | <body> | ||
+ | <form id="ahmed"> | ||
+ | <input type="button" onclick="alert(document.forms[0].id);" value="ahmed's form"> | ||
+ | </form> | ||
− | < | + | <form id="osama"> |
− | < | + | <input type="button" onclick="alert(document.forms[1].id);" value="osama's form"> |
− | </ | + | </form> |
− | + | <form id="raghad"> | |
− | + | <input type="button" onclick="alert(document.forms[2].id);" value="raghad's form"> | |
− | <form id=" | + | </form> |
− | + | </body> | |
− | |||
− | |||
− | |||
− | |||
− | </form | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | </body> | ||
</html> | </html> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
سطر 47: | سطر 43: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
الوصول إلى النماذج عبر أسمائها: | الوصول إلى النماذج عبر أسمائها: | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="html"> |
<!DOCTYPE html> | <!DOCTYPE html> | ||
<html lang="en"> | <html lang="en"> | ||
− | <head> | + | <head> |
− | + | <title>document.forms</title> | |
− | </head> | + | </head> |
+ | <body> | ||
+ | <form name="login"> | ||
+ | <input name="email" type="email"> | ||
+ | <input name="password" type="password"> | ||
+ | <button type="submit">Log in</button> | ||
+ | </form> | ||
− | < | + | <script> |
− | + | var loginForm = document.forms.login; // أو document.forms['login'] | |
− | + | loginForm.elements.email.placeholder = 'test@example.com'; | |
− | + | loginForm.elements.password.placeholder = 'password'; | |
− | + | </script> | |
− | + | </body> | |
− | </ | + | </html> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | ==انظر | + | ==انظر أيضًا== |
− | * [[HTML | + | * [[:تصنيف:HTML Forms|نماذج HTML]]. |
− | * [[HTML/form| | + | * العنصر <code>[[HTML/form|<form>]]</code>. |
==مصادر ومواصفات== | ==مصادر ومواصفات== | ||
* مواصفة [https://html.spec.whatwg.org/multipage/#dom-document-forms HTML Living Standard]. | * مواصفة [https://html.spec.whatwg.org/multipage/#dom-document-forms HTML Living Standard]. |
مراجعة 04:24، 21 مارس 2018
تُعيد الخاصّية forms
مجموعة من النّوع HTMLCollection
تحتوي على جميع عناصِر <form>
في المُستند.
ملاحظة: يُمكنك كذلك استعمال الخاصيّة HTMLFormElement.elements
للحصول على قائمةٍ بعناصِر نماذج الإدخال بشكلٍ مُشابه.
البنية العامة
collection = document.forms;
القيمة
كائنٌ من النّوع HTMLCollection
يُمثّل قائمةً بجميع النّماذج في المُستند. كلّ عنصر من المجموعة يُعدّ من النّوع HTMLFormElement
ويُمثّل عنصر <form>
وحيد.
إن لم يوجد أي نموذج في المُستند، فالمجموعة المُعادة ستكون فارغة بطولٍ يُساوي صفرًا.
أمثلة
الحصول على معلومات نموذج مُعيّن:
<!DOCTYPE html>
<html lang="en">
<head>
<title>document.forms</title>
</head>
<body>
<form id="ahmed">
<input type="button" onclick="alert(document.forms[0].id);" value="ahmed's form">
</form>
<form id="osama">
<input type="button" onclick="alert(document.forms[1].id);" value="osama's form">
</form>
<form id="raghad">
<input type="button" onclick="alert(document.forms[2].id);" value="raghad's form">
</form>
</body>
</html>
الحصول على عنصرٍ داخل النّموذج:
var selectForm = document.forms[index];
var selectFormElement = document.forms[index].elements[index];
الوصول إلى النماذج عبر أسمائها:
<!DOCTYPE html>
<html lang="en">
<head>
<title>document.forms</title>
</head>
<body>
<form name="login">
<input name="email" type="email">
<input name="password" type="password">
<button type="submit">Log in</button>
</form>
<script>
var loginForm = document.forms.login; // أو document.forms['login']
loginForm.elements.email.placeholder = 'test@example.com';
loginForm.elements.password.placeholder = 'password';
</script>
</body>
</html>
انظر أيضًا
- نماذج HTML.
- العنصر
<form>
.