blob: 1fd4533c77f6f80b8d07bc001e23dc980d8ecd4f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
---
title: insertItemAt
slug: Archive/Mozilla/XUL/Method/insertItemAt
tags:
- XUL Methods
- XUL Reference
translation_of: Archive/Mozilla/XUL/Method/insertItemAt
---
<div class="noinclude">
<span class="breadcrumbs XULRefMeth_breadcrumbs">« <a href="/ja/docs/XUL_Reference" title="/ja/docs/XUL_Reference">XUL リファレンス HOME</a></span></div>
<dl>
<dt><span id="m-insertItemAt"><code><a href="https://developer.mozilla.org/ja/docs/Mozilla/Tech/XUL/Method/insertItemAt">insertItemAt( index, label, value )</a></code></span></dt>
<dd>戻り値の型: <em>要素</em></dd>
<dd>このメソッドは新しい項目を生成し、それを指定した位置に挿入します。値の設定は任意です。新しい項目要素を返します。</dd>
</dl>
<div class="noinclude">
<p><strong>注意:</strong> 存在しない <var>index</var> に項目を挿入することはできません。例: <code>element.getRowCount() + 1</code> で末尾に項目を挿入する。</p>
<h3 id="Example" name="Example">例</h3>
<pre class="brush:js"><!-- 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>
</pre>
<h3 id="See_also" name="See_also">関連情報</h3>
<ul>
<li><a href="/ja/docs/XUL/Method/appendItem"><code>appendItem()</code></a></li>
<li><a href="/ja/docs/XUL/Method/removeItemAt"><code>removeItemAt()</code></a></li>
</ul>
</div>
|