Option index attribute

Definition and Usage

index Sets or returns the index position of the option in the drop-down list.

Indexes (indices) start from 0.

See also:

HTML Reference Manual:ແຕ່ງຕັ້ງ <option> HTML

Instance

Example 1

Display the index and text of the selected option in the drop-down list:

var x = document.getElementById("mySelect").selectedIndex;
var y = document.getElementById("mySelect").options;
alert("Index: " + y[x].index + " is " + y[x].text);

ທ່ານຕ້ອງຊອກບຸກຄືນ

Example 2

Display all text and index of options in the drop-down list:

var x = document.getElementById("mySelect");
var txt = "All options: ";
var i;
for (i = 0; i < x.length; i++) {
    txt = txt + "\n" + x.options[i].text + " has index: " + x.options[i].index;
}

ທ່ານຕ້ອງຊອກບຸກຄືນ

ວິທິການ

ການກັບຄືນ index:

optionObject.index

ການຕັ້ງຂໍ້ມູນ index:

optionObject.index = integer

ຄວາມລວມຂອງບັນດາປະກອບ

ຄວາມລວມ ການອະທິບາຍ
integer ກໍານົດຈຳນວນອີກຂອງຕົວເລື່ອງໃນລະບົບອັນສາວິດ.

ລະອຽດດ້ານເຕັກນິກ

ຜົນກະທົບ: ຈຳນວນ, ທີ່ສະແດງຈຳນວນອີກຂອງຕົວເລື່ອງໃນລະບົບອັນສາວິດ. ບໍ່ມີຈຳນວນສະແດງຈາກ 0.

ການສະໜັບສະໜູນບັນດາບານສະແດງ

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
ສະໜັບສະໜູນ ສະໜັບສະໜູນ ສະໜັບສະໜູນ ສະໜັບສະໜູນ ສະໜັບສະໜູນ