Id (JavaScript) yordamida elementga kirish

Stsenariy: id = "shipping_address" bilan ariza elementi bor

Quyidagi ishlarning barchasi:

var i = document.shipping_address;
var i = window.shipping_address;
var i = shipping_address;

var i = document.forms.shipping_address;
var i = windows.forms.shipping_address;
var i = forms.shipping_address:

Oldindan rahmat!

5

7 javoblar

Elementning identifikatoriga murojaat qilish orqali element qiymatini olish uchun foydalaning:

document.getElementById('shipping_address').value;
1
qo'shib qo'ydi

Elementning identifikatoriga murojaat qilish orqali element qiymatini olish uchun foydalaning:

document.getElementById('shipping_address').value;
1
qo'shib qo'ydi

Hammasini Codepen.io-da sinashingiz mumkin, lekin men faqatgina foydalanmoqchi edim:

var i = document.getElementById("shipping_address");

Keyin kerakli narsaga ko'ra, bu erda ko'rsatilgan barcha xususiyatlar ga kiring.

0
qo'shib qo'ydi

Ishlaydigan misol:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

var i = document.shipping_address;
console.log(i);
var i = window.shipping_address;
console.log(i);
var i = shipping_address;
console.log(i);
var i = document.forms.shipping_address;
console.log(i);
var i = windows.forms.shipping_address;
console.log(i);
var i = forms.shipping_address;
console.log(i);
<form id="shipping_address">
  <input type='text'/>
</form>
</div> </div>

Men sizga yordam berish uchun JSFiddle yaratdim.

https://jsfiddle.net/hszknwn9/1/

iltimos, oxirgi satrda xat yozuvchilik deb o'ylayman: var i =

forms.shipping_address:

a: a bo'lishi kerak;

Uni jsFiddle formatida tuzatdim

0
qo'shib qo'ydi

Ishlaydigan misol:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

var i = document.shipping_address;
console.log(i);
var i = window.shipping_address;
console.log(i);
var i = shipping_address;
console.log(i);
var i = document.forms.shipping_address;
console.log(i);
var i = windows.forms.shipping_address;
console.log(i);
var i = forms.shipping_address;
console.log(i);
<form id="shipping_address">
  <input type='text'/>
</form>
</div> </div>

Men sizga yordam berish uchun JSFiddle yaratdim.

https://jsfiddle.net/hszknwn9/1/

iltimos, oxirgi satrda xat yozuvchilik deb o'ylayman: var i =

forms.shipping_address:

a: a bo'lishi kerak;

Uni jsFiddle formatida tuzatdim

0
qo'shib qo'ydi

Ular ishlamaydi.

Agar elementingizning namunasini id = "shipping_address" bilan belgilashga harakat qilmoqchi bo'lsangiz, to'g'ri yo'l shunday bo'ladi:

var i = document.getElementById("shipping_address");

To access the individual fields (and their respective contents) of that element, you need to first access the array of elements in your <form> element, and then iterate through:

var fields = i.elements;
var responses = [];
for(var j = 0; j < fields.length; j++) {
    //perform actions on or with fields[j],
   //such as responses.push(fields[j].value);
   //which would put the value of each field
   //of the form into the responses array.
}

The <form> element is a special container for grouping individual <input> elements, each of which should specify its input type. For example,

<form id="shipping_address">
<input type="text" placeholder="Street Address/P.O. box">
<input type="text" placeholder="Town/City Name">
<input type="text" placeholder="State/Country Name">
<input type="text" placeholder="Zip Code (if applicable)">
</form>

Qaysi kirishlar to'planishi mumkin bo'lgan 4 ta oddiy matnli maydon yaratadi. Bularning barchasini bir joyga qo'yish uchun shipping_address formadagi elementingizning barcha qiymatlarini o'z ichiga olgan qatorni qaytaradigan funksiyani yaratishimiz mumkin:

function getAddress() {
    var i = document.getElementById("shipping_address");
    var fields = i.elements;
    var responses = [];
    for(var j = 0; j < fields.length; j++) {
        responses.push(fields[j].value);
    return responses;
}

Va u erdan siz xohlagan ma'lumotlarga ega bo'lishingiz mumkin.

tipidagi larning ko'pligi mavjud bo'lsa, men sizga w3schools HTML fayli mos yozuvlar , bu elementlarning aksariyati uchun maqbul hujjatlarni taqdim etadi.

Umid qilamanki bu yordam!

0
qo'shib qo'ydi

Ular ishlamaydi.

Agar elementingizning namunasini id = "shipping_address" bilan belgilashga harakat qilmoqchi bo'lsangiz, to'g'ri yo'l shunday bo'ladi:

var i = document.getElementById("shipping_address");

To access the individual fields (and their respective contents) of that element, you need to first access the array of elements in your <form> element, and then iterate through:

var fields = i.elements;
var responses = [];
for(var j = 0; j < fields.length; j++) {
    //perform actions on or with fields[j],
   //such as responses.push(fields[j].value);
   //which would put the value of each field
   //of the form into the responses array.
}

The <form> element is a special container for grouping individual <input> elements, each of which should specify its input type. For example,

<form id="shipping_address">
<input type="text" placeholder="Street Address/P.O. box">
<input type="text" placeholder="Town/City Name">
<input type="text" placeholder="State/Country Name">
<input type="text" placeholder="Zip Code (if applicable)">
</form>

Qaysi kirishlar to'planishi mumkin bo'lgan 4 ta oddiy matnli maydon yaratadi. Bularning barchasini bir joyga qo'yish uchun shipping_address formadagi elementingizning barcha qiymatlarini o'z ichiga olgan qatorni qaytaradigan funksiyani yaratishimiz mumkin:

function getAddress() {
    var i = document.getElementById("shipping_address");
    var fields = i.elements;
    var responses = [];
    for(var j = 0; j < fields.length; j++) {
        responses.push(fields[j].value);
    return responses;
}

Va u erdan siz xohlagan ma'lumotlarga ega bo'lishingiz mumkin.

tipidagi larning ko'pligi mavjud bo'lsa, men sizga w3schools HTML fayli mos yozuvlar , bu elementlarning aksariyati uchun maqbul hujjatlarni taqdim etadi.

Umid qilamanki bu yordam!

0
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb