insertItemAt( index, label, value )
戻り値の型: 要素

注意: 存在しない index に項目を挿入することはできません。例: element.getRowCount() + 1 で末尾に項目を挿入する。

<!-- This example inserts at the selected item or appends, then selects the newly created item -->
<script language="javascript">
function insertItemToList() {
  var myListBox = document.getElementById('myListBox');

  // create a date to get some labels and values
  var someDate = new Date();

  if(myListBox.selectedIndex == -1){
    // no item was selected in list so append to the end
    myListBox.appendItem( someDate.toLocaleTimeString(), someDate.getTime() );
    var newIndex = myListBox.getRowCount()  -1
  } else {
    // item was selected so insert at the selected item
    var newIndex =  myListBox.selectedIndex;
    myListBox.insertItemAt(newIndex, someDate.toLocaleTimeString(), someDate.getTime());

  // select the newly created item
  myListBox.selectedIndex = newIndex;

<button label="Insert item at selected" oncommand="insertItemToList()" />

<listbox id="myListBox">
    <listitem label="foo" />



 このページの貢献者: ethertank, Marsf
 最終更新者: ethertank,