From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../mozilla/xul/method/insertitemat/index.html | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 files/ja/archive/mozilla/xul/method/insertitemat/index.html (limited to 'files/ja/archive/mozilla/xul/method/insertitemat/index.html') diff --git a/files/ja/archive/mozilla/xul/method/insertitemat/index.html b/files/ja/archive/mozilla/xul/method/insertitemat/index.html new file mode 100644 index 0000000000..1fd4533c77 --- /dev/null +++ b/files/ja/archive/mozilla/xul/method/insertitemat/index.html @@ -0,0 +1,56 @@ +--- +title: insertItemAt +slug: Archive/Mozilla/XUL/Method/insertItemAt +tags: + - XUL Methods + - XUL Reference +translation_of: Archive/Mozilla/XUL/Method/insertItemAt +--- +
+ « XUL リファレンス HOME
+
+
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;
+}
+</script>
+
+<button label="Insert item at selected" oncommand="insertItemToList()" />
+
+<listbox id="myListBox">
+    <listitem label="foo" />
+</listbox>
+
+ +

関連情報

+ + +
-- cgit v1.2.3-54-g00ecf