From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/htmlinputelement/index.html | 428 +++++++++++++++++++++ .../api/htmlinputelement/invalid_event/index.html | 112 ++++++ .../mozgetfilenamearray/index.html | 47 +++ .../web/api/htmlinputelement/multiple/index.html | 38 ++ .../ja/web/api/htmlinputelement/select/index.html | 85 ++++ .../api/htmlinputelement/setrangetext/index.html | 101 +++++ .../htmlinputelement/setselectionrange/index.html | 115 ++++++ .../htmlinputelement/webkitdirectory/index.html | 140 +++++++ 8 files changed, 1066 insertions(+) create mode 100644 files/ja/web/api/htmlinputelement/index.html create mode 100644 files/ja/web/api/htmlinputelement/invalid_event/index.html create mode 100644 files/ja/web/api/htmlinputelement/mozgetfilenamearray/index.html create mode 100644 files/ja/web/api/htmlinputelement/multiple/index.html create mode 100644 files/ja/web/api/htmlinputelement/select/index.html create mode 100644 files/ja/web/api/htmlinputelement/setrangetext/index.html create mode 100644 files/ja/web/api/htmlinputelement/setselectionrange/index.html create mode 100644 files/ja/web/api/htmlinputelement/webkitdirectory/index.html (limited to 'files/ja/web/api/htmlinputelement') diff --git a/files/ja/web/api/htmlinputelement/index.html b/files/ja/web/api/htmlinputelement/index.html new file mode 100644 index 0000000000..f9fe5bf72b --- /dev/null +++ b/files/ja/web/api/htmlinputelement/index.html @@ -0,0 +1,428 @@ +--- +title: HTMLInputElement +slug: Web/API/HTMLInputElement +tags: + - API + - DOM + - HTML DOM + - HTMLInputElement + - Input + - Interface + - NeedsContent + - NeedsMarkupWork + - Reference +translation_of: Web/API/HTMLInputElement +--- +
{{ APIRef("HTML DOM") }}
+ +

HTMLInputElement インターフェイスは {{HtmlElement("input")}} 要素のオプション、レイアウト、表示を操作するための特別なプロパティやメソッドを提供します。

+ +

{{InheritanceDiagram(600, 120)}}

+ +

プロパティ

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
親フォームに関連するプロパティ
form {{readonlyInline}}{{domxref("HTMLFormElement")}} オブジェクト: 親の {{HtmlElement("form")}} 要素の参照を返します
formActionstring: その要素の {{ htmlattrxref("formaction", "input") }} 属性を返却または設定します。ここには要素によって送信された情報を処理するプログラムの URI が入ります。これは親フォームの {{ htmlattrxref("action", "form") }} 属性を上書きします。
formEncTypestring: その要素の {{ htmlattrxref("formenctype", "input") }} 属性を返却または設定します。ここにはフォームをサーバーに送信する際のコンテンツの型が入ります。これは親フォームの {{ htmlattrxref("enctype", "form") }} 属性を上書きします。
formMethodstring: その要素の {{ htmlattrxref("formmethod", "input") }} 属性を返却または設定します。ここにはブラウザーがフォームを送信する際に用いる HTTP メソッドが入ります。これは親フォームの {{ htmlattrxref("method", "form") }} 属性を上書きします。
formNoValidate{{jsxref("Boolean")}}: その要素の {{ htmlattrxref("formnovalidate", "input") }} 属性を返却または設定します。これは送信時にそのフォームが検証されないかどうかを示します。これは親フォームの {{ htmlattrxref("novalidate", "form") }} 属性を上書きします。
formTargetstring: その要素の {{ htmlattrxref("formtarget", "input") }} 属性を返却または設定します。ここにはフォームを送信した後で受け取ったレスポンスを表示する場所を示す名前またはキーワードが入ります。これは親フォームの {{ htmlattrxref("target", "form") }} 属性を上書きします。
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
hidden 以外のあらゆる型の入力要素に適用されるプロパティ
namestring: その要素の {{ htmlattrxref("name", "input") }} 属性を返却または設定します。ここにはフォーム送信時にその要素を識別する名前が入ります。
typestring: その要素の {{ htmlattrxref("type", "input") }} 属性を返却または設定します。これは表示するコントロールの型を示します。利用可能な値については {{ HTMLElement("input") }} の {{ htmlattrxref("type", "input") }} 属性を参照してください。
disabled{{jsxref("Boolean")}}: その要素の {{ htmlattrxref("disabled", "input") }} 属性を返却または設定します。これはそのコントロールが対話を受け付けないかどうかを示します。その入力値はフォームとともに送信されません。 {{ htmlattrxref("readOnly", "input") }} もご覧ください。
autofocus{{jsxref("Boolean")}}: その要素の {{ htmlattrxref("autofocus", "input") }} 属性を返却または設定します。ページが読み込まれたときに、ユーザーが別のコントロールに入力するなどしてそれを上書きしない限り、そのフォームコントロールが入力フォーカスを持つべきであることを指定します。文書内の一つの form 要素だけが {{htmlattrxref("autofocus","input")}} 属性を持つことができます。 {{htmlattrxref("type","input")}} 属性が hidden に設定されている場合には適用できません (つまり、非表示のコントロールにフォーカスを自動的に設定することはできません)。
required{{jsxref("Boolean")}}: その要素の {{ htmlattrxref("required", "input") }} 属性を返却または設定します。これは、フォームを送信する前にユーザーが値を入力しなければならないかどうかを示します。
valuestring: そのコントロールの現在の値を返却または設定します。 +

注: ユーザーが予期しない値を入力した場合、これは空文字列を返すことがあります。

+
validity {{readonlyInline}}{{domxref("ValidityState")}} オブジェクト: その要素の現在の検証状態を返します
validationMessage {{readonlyInline}}string: 制約検証をそのコントロールが満たさな買った場合、それを記述したローカライズされたメッセージを返します (もしあれば)。これは、コントロールが制約検証の候補ではない場合 ({{htmlattrxref("willValidate","input")}} が false の場合)、または制約を満たしている場合は空の文字列です。この値は、 setCustomValidity メソッドで設定できます。
willValidate {{readonlyInline}}{{jsxref("Boolean")}}: その要素が制約検証の候補であるかどうかを返します。これは何か制約検証を阻む条件がある場合、例えば、 typehidden, reset, button のいずれかである、祖先に {{HTMLElement("datalist")}} がある、 disabled プロパティが true である、などです。
+ + + + + + + + + + + + + + + + + +
checkbox または radio 型の要素にのみに適用できるプロパティ
checked{{jsxref("Boolean")}}: Returns / Sets the current state of the element when {{htmlattrxref("type","input")}} is checkbox or radio.
defaultChecked{{jsxref("Boolean")}}: Returns / Sets the default state of a radio button or checkbox as originally specified in HTML that created this object.
indeterminate{{jsxref("Boolean")}}: Returns whether the checkbox or radio button is in indeterminate state. For checkboxes, the effect is that the appearance of the checkbox is obscured/greyed in some way as to indicate its state is indeterminate (not checked but not unchecked). Does not affect the value of the checked attribute, and clicking the checkbox will set the value to false.
+ + + + + + + + + + + + + + + + + + + + + +
image 型の要素のみに適用できるプロパティ
altstring: Returns / Sets the element's {{ htmlattrxref("alt", "input") }} attribute, containing alternative text to use when {{htmlattrxref("type","input")}} is image.
heightstring: Returns / Sets the element's {{ htmlattrxref("height", "input") }} attribute, which defines the height of the image displayed for the button, if the value of {{htmlattrxref("type","input")}} is image.
srcstring: Returns / Sets the element's {{ htmlattrxref("src", "input") }} attribute, which specifies a URI for the location of an image to display on the graphical submit button, if the value of {{htmlattrxref("type","input")}} is image; otherwise it is ignored.
widthstring: Returns / Sets the document's {{ htmlattrxref("width", "input") }} attribute, which defines the width of the image displayed for the button, if the value of {{htmlattrxref("type","input")}} is image.
+ + + + + + + + + + + + + + + + + + + + + + + + + +
file 型の要素のみに適用できるプロパティ/caption>
acceptstring: Returns / Sets the element's {{ htmlattrxref("accept", "input") }} attribute, containing comma-separated list of file types accepted by the server when {{htmlattrxref("type","input")}} is file.
allowdirs {{non-standard_inline}}{{jsxref("Boolean")}}: Part of the non-standard Directory Upload API; indicates whether or not to allow directories and files both to be selected in the file list. Implemented only in Firefox and is hidden behind a preference.
filesReturns/accepts a {{domxref("FileList")}} object, which contains a list of {{domxref("File")}} objects representing the files selected for upload.
{{domxref("HTMLInputElement.webkitdirectory", "webkitdirectory")}} {{Non-standard_inline}}{{jsxref("Boolean")}}: Returns the {{htmlattrxref("webkitdirectory", "input")}} attribute; if true, the file system picker interface only accepts directories instead of files.
{{domxref("HTMLInputElement.webkitEntries", "webkitEntries")}} {{Non-standard_inline}}Array of {{domxref("FileSystemEntry")}} objects: Describes the currently selected files or directories.
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
text/number を含む型の要素のみに適用できるプロパティ
autocompletestring: Returns / Sets the element's {{htmlattrxref("autocomplete", "input")}} attribute, indicating whether the value of the control can be automatically completed by the browser. Ignored if the value of the {{htmlattrxref("type","input")}} attribute is hidden, checkbox, radio, file, or a button type (button, submit, reset, image). Possible values are:
+ on: the browser can autocomplete the value using previously stored value
+ off: the user must explicity enter a value
maxstring: Returns / Sets the element's {{ htmlattrxref("max", "input") }} attribute, containing the maximum (numeric or date-time) value for this item, which must not be less than its minimum ({{htmlattrxref("min","input")}} attribute) value.
maxLengthlong: Returns / Sets the element's {{ htmlattrxref("maxlength", "input") }} attribute, containing the maximum number of characters (in Unicode code points) that the value can have. (If you set this to a negative number, an exception will be thrown.)
minstring: Returns / Sets the element's {{ htmlattrxref("min", "input") }} attribute, containing the minimum (numeric or date-time) value for this item, which must not be greater than its maximum ({{htmlattrxref("max","input")}} attribute) value.
minLengthlong: Returns / Sets the element's {{ htmlattrxref("minlength", "input") }} attribute, containing the minimum number of characters (in Unicode code points) that the value can have. (If you set this to a negative number, an exception will be thrown.)
patternstring: Returns / Sets the element's {{ htmlattrxref("pattern", "input") }} attribute, containing a regular expression that the control's value is checked against. Use the {{htmlattrxref("title","input")}} attribute to describe the pattern to help the user. This attribute applies when the value of the {{htmlattrxref("type","input")}} attribute is text, search, tel, url or email; otherwise it is ignored.
placeholderstring: Returns / Sets the element's {{ htmlattrxref("placeholder", "input") }} attribute, containing a hint to the user of what can be entered in the control. The placeholder text must not contain carriage returns or line-feeds. This attribute applies when the value of the {{htmlattrxref("type","input")}} attribute is text, search, tel, url or email; otherwise it is ignored.
readOnlyboolean: Returns / Sets the element's {{ htmlattrxref("readonly", "input") }} attribute, indicating that the user cannot modify the value of the control.
+ {{HTMLVersionInline(5)}}This is ignored if the value of the {{htmlattrxref("type","input")}} attribute is hidden, range, color, checkbox, radio, file, or a button type.
selectionStartunsigned long: 選択した文章の開始点を返却・設定する。何も選択していない場合,{{HTMLElement("input")}}要素内の文章入力カーソル(編集子)の位置を返す。
selectionEndunsigned long: Returns / Sets the end index of the selected text. When there's no selection, this returns the offset of the character immediately following the current text input cursor position.
selectionDirectionstring: Returns / Sets the direction in which selection occurred. Possible values are:
+ forward if selection was performed in the start-to-end direction of the current locale
+ backward for the opposite direction
+ none if the direction is unknown
sizeunsigned long: Returns / Sets the element's {{ htmlattrxref("size", "input") }} attribute, containing visual size of the control. This value is in pixels unless the value of {{htmlattrxref("type","input")}} is text or password, in which case, it is an integer number of characters. Applies only when {{htmlattrxref("type","input")}} is set to text, search, tel, url, email, or password; otherwise it is ignored.
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
未分類のプロパティ
defaultValuestring: Returns / Sets the default value as originally specified in the HTML that created this object.
dirNamestring: Returns / Sets the directionality of the element.
accessKeystring: Returns a string containing a single character that switches input focus to the control when pressed.
list {{readonlyInline}}{{domxref("HTMLElement")}} object: Returns the element pointed by the {{ htmlattrxref("list", "input") }} attribute. The property may be null if no HTML element found in the same tree.
multiple{{jsxref("Boolean")}}: Returns / Sets the element's {{ htmlattrxref("multiple", "input") }} attribute, indicating whether more than one value is possible (e.g., multiple files).
files{{domxref("FileList")}} array: Returns the list of selected files.
{{domxref("HTMLInputElement.labels")}} {{readonlyInline}}{{domxref("NodeList")}} array: Returns a list of {{ HTMLElement("label") }} elements that are labels for this element.
stepstring: Returns / Sets the element's {{ htmlattrxref("step", "input") }} attribute, which works with {{htmlattrxref("min","input")}} and {{htmlattrxref("max","input")}} to limit the increments at which a numeric or date-time value can be set. It can be the string any or a positive floating point number. If this is not set to any, the control accepts only values at multiples of the step value greater than the minimum.
valueAsDate{{jsxref("Date")}} object: Returns / Sets the value of the element, interpreted as a date, or null if conversion is not possible.
valueAsNumberdouble: Returns the value of the element, interpreted as one of the following, in order: +
    +
  • A time value
  • +
  • A number
  • +
  • NaN if conversion is impossible
  • +
+
autocapitalize {{experimental_inline}}string: Defines the capitalization behavior for user input. Valid values are none, off, characters, words, or sentences.
inputmodeProvides a hint to browsers as to the type of virtual keyboard configuration to use when editing this element or its contents.
+ +
+
{{domxref("HTMLInputElement.align")}} {{obsolete_inline}}
+
string: Represents the alignment of the element. Use CSS instead.
+
{{domxref("HTMLInputElement.useMap")}} {{ obsolete_inline }}
+
string: Represents a client-side image map.
+
+ +

メソッド

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{domxref("HTMLElement.blur()", "blur()")}}Removes focus from the input element; keystrokes will subsequently go nowhere.
{{domxref("HTMLElement.click()", "click()")}}Simulates a click on the input element.
{{domxref("HTMLElement.focus()", "focus()")}}Focuses on the input element; keystrokes will subsequently go to this element.
{{domxref("HTMLInputElement.select()", "select()")}}Selects all the text in the input element, and focuses it so the user can subsequently replace all of its content.
{{domxref("HTMLInputElement.setSelectionRange()", "setSelectionRange()")}}Selects a range of text in the input element (but does not focus it).
{{domxref("HTMLInputElement.setRangeText()", "setRangeText()")}}Replaces a range of text in the input element with new text.
setCustomValidity()Sets a custom validity message for the element. If this message is not the empty string, then the element is suffering from a custom validity error, and does not validate.
checkValidity()Returns a {{jsxref("Boolean")}} that is false if the element is a candidate for constraint validation, and it does not satisfy its constraints. In this case, it also fires an {{event("invalid")}} event at the element. It returns true if the element is not a candidate for constraint validation, or if it satisfies its constraints.
reportValidity()Runs the checkValidity() method, and if it returns false (for an invalid input or no pattern attribute provided), then it reports to the user that the input is invalid in the same manner as if you submitted a form.
+ +
+
{{domxref("HTMLInputElement.stepDown()")}}
+
Decrements the {{htmlattrxref("value","input")}} by ({{htmlattrxref("step","input")}} * n), where n defaults to 1 if not specified. Throws an INVALID_STATE_ERR exception: +
    +
  • if the method is not applicable to for the current {{htmlattrxref("type","input")}} value,
  • +
  • if the element has no {{htmlattrxref("step","input")}} value,
  • +
  • if the {{htmlattrxref("value","input")}} cannot be converted to a number,
  • +
  • if the resulting value is above the {{htmlattrxref("max","input")}} or below the {{htmlattrxref("min","input")}}.
  • +
+
+
{{domxref("HTMLInputElement.stepUp()")}}
+
Increments the {{htmlattrxref("value","input")}} by ({{htmlattrxref("step","input")}} * n), where n defaults to 1 if not specified. Throws an INVALID_STATE_ERR exception: +
    +
  • if the method is not applicable to for the current {{htmlattrxref("type","input")}} value.,
  • +
  • if the element has no {{htmlattrxref("step","input")}} value,
  • +
  • if the {{htmlattrxref("value","input")}} cannot be converted to a number,
  • +
  • if the resulting value is above the {{htmlattrxref("max","input")}} or below the {{htmlattrxref("min","input")}}.
  • +
+
+
{{domxref("HTMLInputElement.mozSetFileArray()")}} {{non-standard_inline}}
+
Sets the files selected on the input to the given array of {{domxref("File")}} objects. This is an alternative to mozSetFileNameArray() which can be used in frame scripts: a chrome script can open files as File objects and send them via message manager.
+
{{domxref("HTMLInputElement.mozGetFileNameArray()")}} {{non-standard_inline}}
+
Returns an array of all the file names from the input.
+
{{domxref("HTMLInputElement.mozSetFileNameArray()")}} {{non-standard_inline}}
+
Sets the filenames for the files selected on the input. Not for use in frame scripts, because it accesses the file system.
+
+ +

イベント

+ +

Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface:

+ +
+
input
+
Fires when the value of an {{HTMLElement("input")}}, {{HTMLElement("select")}}, or {{HTMLElement("textarea")}} element has been changed. Note that this is actually fired on the {{domxref("HTMLElement")}} interface and also applies to contenteditable elements, but we've listed it here because it is most commonly used with form input elements.
+ Also available via the oninput event handler property.
+
invalid
+
Fired when an element does not satisfy its constraints during constraint validation.
+ Also available via the oninvalid event handler property.
+
search
+
Fired when a search is initiated on an {{HTMLElement("input")}} of type="search".
+ Also available via the onsearch event handler property.
+
+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('HTML WHATWG', "#htmlinputelement", "HTMLInputElement")}}{{Spec2('HTML WHATWG')}}
{{SpecName('HTML5 W3C', "forms.html#the-input-element", "HTMLInputElement")}}{{Spec2('HTML5 W3C')}}技術的には、tabindex プロパティと accesskey プロパティ、ならびに blur()click()、および focus() メソッドは、現在 {{domxref("HTMLElement")}} で定義されています。
+ 次のプロパティは廃止されました: align および useMap
+ 次のプロパティが追加されました: autocomplete, autofocus, dirName, files, formAction, formEncType, formMethod, formNoValidate, formTarget, height, indeterminate, labels, list, max, min, multiple, pattern, placeholder, required, selectionDirection, selectionEnd, selectionStart, step, validationMessage, validity, valueAsDate, valueAsNumber, width, willValidate.
+ 次のメソッドが追加されました: checkValidity(), setCustomValidity(), setSelectionRange(), stepUp(), stepDown()
{{SpecName('DOM2 HTML', 'html.html#ID-6043025', 'HTMLInputElement')}}{{Spec2('DOM2 HTML')}}size プロパティは、unsigned long になりました。type プロパティはすべて小文字で指定する必要があります。
{{SpecName('DOM1', 'level-one-html.html#ID-6043025', 'HTMLInputElement')}}{{Spec2('DOM1')}}初回定義
+ +

ブラウザーの互換性

+ +
+ + +

{{Compat("api.HTMLInputElement")}}

+
+ +

関連情報

+ + diff --git a/files/ja/web/api/htmlinputelement/invalid_event/index.html b/files/ja/web/api/htmlinputelement/invalid_event/index.html new file mode 100644 index 0000000000..c0e7d95f60 --- /dev/null +++ b/files/ja/web/api/htmlinputelement/invalid_event/index.html @@ -0,0 +1,112 @@ +--- +title: 'HTMLInputElement: invalid イベント' +slug: Web/API/HTMLInputElement/invalid_event +tags: + - API + - Constraint Validation API + - Constraint validation + - Event + - Forms + - Reference + - invalid +translation_of: Web/API/HTMLInputElement/invalid_event +--- +

{{APIRef}}

+ +

invalid イベントは、送信可能な要素が制約の検証を受け、制約を満たしていない場合に発行されます。

+ + + + + + + + + + + + + + + + + + + + +
バブリングなし
キャンセル
インターフェイス{{DOMxRef("Event")}}
イベントハンドラープロパティ{{domxref("GlobalEventHandlers.oninvalid")}}
+ +

このイベントは、送信時にフォームの問題の概要を表示するのに便利です。フォームが送信されると、 invalid イベントがそれぞれの妥当ではない状態にあるフォームコントロールで発生します。送信可能な要素が妥当であるかどうかは、その所有者である {{HtmlElement("form")}} を送信する前、またはその要素またはその所有者である <form>checkValidity() メソッドが呼び出された後にチェックされます。

+ +

{{domxref("Element/blur_event", "blur")}} ではチェックが行われません。

+ +

+ +

フォームが無効な値で送信された場合、送信可能な要素がチェックされ、エラーが見つかった場合、無効な要素で invalid イベントが発生します。この例では、入力に無効な値があったために invalid イベントが発生した場合、無効な値がログに記録されます。

+ +

HTML

+ +
<form action="#">
+  <ul>
+    <li><label>Enter an integer between 1 and 10: <input type="number" min="1" max="10" required></label></li>
+    <li><input type="submit" value="submit"></li>
+  </ul>
+</form><p id="log"></p>
+ +

JavaScript

+ +
const input = document.querySelector('input')
+const log = document.getElementById('log')
+
+input.addEventListener('invalid', logValue)
+
+function logValue(e) {
+  log.textContent += e.target.value
+}
+ +

結果

+ +

{{EmbedLiveSample("Examples")}}

+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{ SpecName('HTML WHATWG', 'forms.html#the-constraint-validation-api', 'Invalid event') }}{{Spec2('HTML WHATWG')}}
{{ SpecName('HTML5.1', 'sec-forms.html#the-constraint-validation-api', 'Invalid event') }}{{Spec2('HTML5.1')}}
{{ SpecName('HTML5 W3C', 'forms.html#the-constraint-validation-api', 'Invalid event') }}{{Spec2('HTML5 W3C')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.HTMLInputElement.invalid_event")}}

+ +

関連情報

+ + diff --git a/files/ja/web/api/htmlinputelement/mozgetfilenamearray/index.html b/files/ja/web/api/htmlinputelement/mozgetfilenamearray/index.html new file mode 100644 index 0000000000..4148d4abf4 --- /dev/null +++ b/files/ja/web/api/htmlinputelement/mozgetfilenamearray/index.html @@ -0,0 +1,47 @@ +--- +title: HTMLInputElement.mozGetFileNameArray() +slug: Web/API/HTMLInputElement/mozGetFileNameArray +translation_of: Web/API/HTMLInputElement/mozGetFileNameArray +--- +
{{ APIRef("HTML DOM") }}{{Non-standard_header}}
+ +

HTMLInputElement.mozGetFileNameArray()メソッドはHTMLのinput要素上でユーザーによって選択されたファイルの名前の配列を返します。

+ +
Note: このメソッドはGeckoに特有のものであり、他のブラウザでは利用できません。加えて、Webページで利用した場合にエラーが発生します。
+ +

構文

+ +
inputElement.mozGetFileNameArray(aLength, aFileNames);
+
+ +

パラメーター

+ +
+
aLength
+
If specified, will receive the number of file names in the returned array.
+
aFileNames
+
Is an array into which the file names are placed.
+
+ + + +

+ +
var numFiles = 0;
+var fileArray = {};
+
+inputElement.mozGetFileNameArray(numFiles, fileArray);
+
+ +

仕様

+ +

Mozillaに特有のメソッドであり、どの仕様にも書かれていません。

+ +

関連情報

+ + diff --git a/files/ja/web/api/htmlinputelement/multiple/index.html b/files/ja/web/api/htmlinputelement/multiple/index.html new file mode 100644 index 0000000000..a95fa672b3 --- /dev/null +++ b/files/ja/web/api/htmlinputelement/multiple/index.html @@ -0,0 +1,38 @@ +--- +title: HTMLInputElement.multiple +slug: Web/API/HTMLInputElement/multiple +translation_of: Web/API/HTMLInputElement/multiple +--- +
{{ APIRef("HTML DOM") }}
+ +

HTMLInputElement.multipleinputタグが複数の値を持つことができるかどうかを示すプロパティです。現在Firefoxでは、multiple属性は<input type="file">でのみサポートされています。

+ +

+ +
// fileInputは<input type=file multiple>であるようなHTML要素です
+var fileInput = document.getElementById("myfileinput");
+
+if (fileInput.multiple == true) {
+
+    for (var i = 0, len = fileInput.files.length; i < len; i++) {
+        // fileInput.filesをループ
+    }
+
+// 一つのファイルのみが有効な場合
+} else {
+    var file = fileInput.files.item(0);
+}
+
+ +

関連情報

+ + + +

仕様

+ + diff --git a/files/ja/web/api/htmlinputelement/select/index.html b/files/ja/web/api/htmlinputelement/select/index.html new file mode 100644 index 0000000000..5fb740e691 --- /dev/null +++ b/files/ja/web/api/htmlinputelement/select/index.html @@ -0,0 +1,85 @@ +--- +title: HTMLInputElement.select() +slug: Web/API/HTMLInputElement/select +tags: + - API + - HTML DOM + - HTMLInputElement + - Method + - Reference +translation_of: Web/API/HTMLInputElement/select +--- +
{{ APIRef("HTML DOM") }}
+ +

HTMLInputElement.select() メソッドは、{{HTMLElement("textarea")}} 要素またはテキストフィールドを含む {{HTMLElement("input")}} 要素内のすべてのテキストを選択します。

+ +

シンタックス

+ +
element.select();
+ +

+ +

この例のボタンをクリックすると、<input> 要素内のすべてのテキストが選択されます。

+ +

HTML

+ +
<input type="text" id="text-box" size="20" value="Hello world!">
+<button onclick="selectText()">Select text</button>
+
+ +

JavaScript

+ +
function selectText() {
+  const input = document.getElementById('text-box');
+  input.focus();
+  input.select();
+}
+ +

結果

+ +

{{EmbedLiveSample("Example")}}

+ +

メモ

+ +

element.select() を呼んだからといって必ずしも入力がフォーカスされるわけではないので、{{domxref("HTMLElement.focus()")}} で使うことが多いです。

+ +

これがサポートされていないブラウザでは、パラメータ 0 と入力値の長さを指定して HTMLInputElement.setSelectionRange() を呼び出すことで置き換えることができます。

+ +
<input onClick="this.select();" value="Sample Text" />
+<!-- equivalent to -->
+<input onClick="this.setSelectionRange(0, this.value.length);" value="Sample Text" />
+
+ +

仕様

+ + + + + + + + + + + + + + + + +
仕様書ステータスコメント
{{SpecName('HTML WHATWG', 'forms.html#dom-textarea/input-select', 'select')}}{{Spec2('HTML WHATWG')}}
+ +

ブラウザの互換性

+ + + +

{{Compat("api.HTMLInputElement.select")}}

+ +

あわせて参照

+ + diff --git a/files/ja/web/api/htmlinputelement/setrangetext/index.html b/files/ja/web/api/htmlinputelement/setrangetext/index.html new file mode 100644 index 0000000000..06d23ddd27 --- /dev/null +++ b/files/ja/web/api/htmlinputelement/setrangetext/index.html @@ -0,0 +1,101 @@ +--- +title: HTMLInputElement.setRangeText() +slug: Web/API/HTMLInputElement/setRangeText +tags: + - API + - HTMLInputElement +translation_of: Web/API/HTMLInputElement/setRangeText +--- +
{{APIRef("HTML DOM")}}
+ +

HTMLInputElement.setRangeText() メソッドを用いて,{{HTMLElement("input")}}や{{HTMLElement("textarea")}}要素において,文章の指定した範囲を新たな文字列で置き換えられます。

+ +

構文

+ +
element.setRangeText(置換対象);
+element.setRangeText(置換対象, 開始, 終了 [, 選択状態]);
+
+ +

引数

+ +
+
置換対象
+
挿入する文字列。
+
開始{{optional_inline}}
+
置き換える最初の文字の位置を0始まりで指定します。既定は現在のselectionStartの値(利用者が現在選択している範囲の始め)です。
+
終了{{optional_inline}}
+
置き換える最初の文字の一つ後の位置を0始まりで指定します。既定は現在のselectionEndの値(利用者が現在選択している範囲の終わり)です。
+
選択状態{{optional_inline}}
+
文章が置換された後,選択範囲がどのように振る舞うべきかを指定します。
+ 次の値が有効です: +
    +
  • select: 新規挿入した文章を選択する。
  • +
  • start: 挿入した文書の直前に選択範囲を移動する。
  • +
  • end: 挿入した文書の直後に選択範囲を移動する。
  • +
  • preserve: 選択範囲を保持しようとします。既定です。
  • +
+
+
+ +

事例

+ +

例中のボタンを押して,欄内の文章の一部を置換してみてください。新規挿入された文章は,その後強調(選択)されるでしょう。

+ +

HTML

+ +
<input type="text" id="text-box" size="18" value="この文章は更新されていません。"/>
+<button onclick="selectText()">文章を更新する</button>
+
+ +

JavaScript

+ +
function selectText() {
+  const input = document.getElementById('text-box');
+  input.focus();
+  input.setRangeText('ました', 9, 14, 'select');
+}
+ +

結果

+ +

{{EmbedLiveSample("Example")}}

+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName("HTML WHATWG", "forms.html#dom-textarea/input-setrangetext", "HTMLInputElement.setSelectionRange()")}}{{Spec2("HTML WHATWG")}}変更なし
{{SpecName("HTML5 W3C", "forms.html#dom-textarea/input-setrangetext", "HTMLInputElement.setSelectionRange()")}}{{Spec2("HTML5 W3C")}}初回定義
+ +

ブラウザ互換性

+ +
+ + +

{{Compat("api.HTMLInputElement.setRangeText")}}

+
+ +

関連項目

+ + diff --git a/files/ja/web/api/htmlinputelement/setselectionrange/index.html b/files/ja/web/api/htmlinputelement/setselectionrange/index.html new file mode 100644 index 0000000000..a984b07e90 --- /dev/null +++ b/files/ja/web/api/htmlinputelement/setselectionrange/index.html @@ -0,0 +1,115 @@ +--- +title: HTMLInputElement.setSelectionRange() +slug: Web/API/HTMLInputElement/setSelectionRange +tags: + - API + - HTML DOM + - HTMLInputElement + - Method + - Reference + - Text Field Selection API +translation_of: Web/API/HTMLInputElement/setSelectionRange +--- +
{{APIRef("HTML DOM")}}
+ +

HTMLInputElement.setSelectionRange() 関数は{{HTMLElement("input")}}または、{{HTMLElement("textarea")}}要素に対して有効です。要素に対して任意の開始と末尾のポジションを設定することでテキストを選択状態にします。

+ +

更に、より新しいブラウザでは選択する方向をも考慮する必要があります。つまり、ユーザーがクリックした後ドラッグして選択状態にする際のドラッグの方向が、はじめからなのか、おしりからなのか、考慮するということです。

+ +

この関数はアップデートされ、HTMLInputElement.selectionStart, selectionEnd, and selectionDirectionプロパティを一度に呼び出し更新することができます。

+ +

Note that accordingly to the WHATWG forms spec selectionStart, selectionEnd properties and setSelectionRange method apply only to inputs of types text, search, URL, tel and password. Chrome, starting from version 33, throws an exception while accessing those properties and method on the rest of input types. For example, on input of type number: "Failed to read the 'selectionStart' property from 'HTMLInputElement': The input element's type ('number') does not support selection.".

+ +

 

+ +

Syntax

+ +
element.setSelectionRange(selectionStart, selectionEnd [, selectionDirection]);
+
+ +

Parameters

+ +

selectionEnd がselectionStartより小さい場合、両方の値はselectionEndとして扱われます。

+ +
+
selectionStart
+
0を基準とした選択状態の文字のインデックス。指定されたインデックスが文字の長さより長い場合は、文字の長さをインデックスに指定したものとみなされます。
+
selectionEnd
+
0を基準とした選択状態の最後の文字のインデックス。指定されたインデックスが文字の長さより長い場合は、文字の長さをインデックスに指定したものとみなされます。
+
selectionDirection {{optional_inline}}
+
選択する際の方向を指定します。取りうる値は以下のとおりです。 +
    +
  • "forward"
  • +
  • "backward"
  • +
  • "none" 選択する際の方向が指定されていない時です。デフォルト値になります。
  • +
+
+
+ +

Example

+ +

サンプルの中のボタンをクリックすると、テキストボックスの3,4,5番目の文字が選択状態になります。 ("Mozilla"の"zil").

+ +

HTML

+ +
<input type="text" id="text-box" size="20" value="Mozilla">
+<button onclick="selectText()">Select text</button>
+
+ +

JavaScript

+ +
function selectText() {
+  const input = document.getElementById('text-box');
+  input.focus();
+  input.setSelectionRange(2, 5);
+}
+ +

実行結果

+ +

{{EmbedLiveSample("Example")}}

+ +

仕様

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("HTML WHATWG", "forms.html#dom-textarea/input-setselectionrange", "HTMLInputElement.setSelectionRange()")}}{{Spec2("HTML WHATWG")}}No change
{{SpecName("HTML5.1", "forms.html#dom-textarea/input-setselectionrange", "HTMLInputElement.setSelectionRange()")}}{{Spec2("HTML5.1")}}No change
{{SpecName("HTML5 W3C", "forms.html#dom-textarea/input-setselectionrange", "HTMLInputElement.setSelectionRange()")}}{{Spec2("HTML5 W3C")}}Initial definition
+ +

ブラウザ互換性

+ +
+ + +

{{Compat("api.HTMLInputElement.setSelectionRange")}}

+
+ +

参照

+ + diff --git a/files/ja/web/api/htmlinputelement/webkitdirectory/index.html b/files/ja/web/api/htmlinputelement/webkitdirectory/index.html new file mode 100644 index 0000000000..05dd96acbd --- /dev/null +++ b/files/ja/web/api/htmlinputelement/webkitdirectory/index.html @@ -0,0 +1,140 @@ +--- +title: HTMLInputElement.webkitDirectory +slug: Web/API/HTMLInputElement/webkitDirectory +tags: + - API + - File System API + - File and Directory Entries API + - Files + - HTML DOM + - HTMLInputElement + - Non-standard + - Property + - Reference + - Web + - webkitdirectory + - プロパティ +translation_of: Web/API/HTMLInputElement/webkitdirectory +--- +

{{APIRef("HTML DOM")}}{{non-standard_header}}

+ +

HTMLInputElement.webkitDirectory プロパティで、 {{htmlattrxref("webkitdirectory", "input")}} という HTML 属性の値を反映し、 {{HTMLElement("input")}} 要素によってユーザーがファイルの代わりにディレクトリを選択できることを示します。ディレクトリが選択された場合、ディレクトリとその内容の階層構造が選択されたアイテムのセットに含まれます。選択されているファイルシステムのファイルアイテムは、 {{domxref("HTMLInputElement.webkitEntries", "webkitEntries")}} を使用して受け取ることができます。

+ +

構文

+ +
 HTMLInputElement.webkitdirectory = boolValue
+ +

+ +

論理型で、 true は {{HTMLElement("input")}} 要素がディレクトリの身を選択することができることを、 false はファイルのみが選択できることを示します。

+ +

結果を理解する

+ +

ユーザーが選択を行った後、 files の中のそれぞれの {{domxref("File")}} オブジェクトは各自が {{domxref("File.webkitRelativePath")}} プロパティセットを持ち、ファイルが所在する位置が選択されたディレクトリの中の相対パスで設定されます。例えば、次のようなファイルシステムを考えてみてください。

+ + + +

ユーザーが PhotoAlbums を選択すると、 files によって報告されるリストは上記のすべてのファイルに対する {{domxref("File")}} オブジェクトを含みます。 — しかし、ディレクトリは含みません。 PIC2343.jpg のエントリでは webkitRelativePathPhotoAlbums/Birthdays/Don's 40th birthday/PIC2343.jpg となりますこれによって {{domxref("FileList")}} がフラットでも階層構造を知ることができます。

+ +
+

メモ: webkitRelativePath の挙動は Chromium < 72 では異なります。詳しくはこのバグを参照してください。

+
+ +

+ +

この例では、ユーザーが1つまたは複数のディレクトリを選択することができるディレクトリピッカーが表示されます。 {{event("change")}} イベントが発生すると、選択されたディレクトリ階層ないのすべてのファイルを含むリストが生成され、表示されます。

+ +

HTML content

+ +
<input type="file" id="filepicker" name="fileList" webkitdirectory multiple />
+<ul id="listing"></ul>
+ +

JavaScript content

+ +
document.getElementById("filepicker").addEventListener("change", function(event) {
+  let output = document.getElementById("listing");
+  let files = event.target.files;
+
+  for (let i=0; i<files.length; i++) {
+    let item = document.createElement("li");
+    item.innerHTML = files[i].webkitRelativePath;
+    output.appendChild(item);
+  };
+}, false);
+
+ +

結果

+ +

{{ EmbedLiveSample('Example') }}

+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{ SpecName('File System API', '#dom-htmlinputelement-webkitdirectory', 'webkitdirectory') }}{{ Spec2('File System API') }}初回定義
+ +

This API has no official W3C or WHATWG specification.

+ +

ブラウザーの互換性

+ + + +

{{Compat("api.HTMLInputElement.webkitdirectory")}}

+ +

関連情報

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