diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/archive/mozilla/xul/method/insertitemat/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/ja/archive/mozilla/xul/method/insertitemat/index.html')
-rw-r--r-- | files/ja/archive/mozilla/xul/method/insertitemat/index.html | 56 |
1 files changed, 56 insertions, 0 deletions
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 +--- +<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> |