aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/api/htmloptionelement
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
commit074785cea106179cb3305637055ab0a009ca74f2 (patch)
treee6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/pt-br/web/api/htmloptionelement
parentda78a9e329e272dedb2400b79a3bdeebff387d47 (diff)
downloadtranslated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz
translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2
translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip
initial commit
Diffstat (limited to 'files/pt-br/web/api/htmloptionelement')
-rw-r--r--files/pt-br/web/api/htmloptionelement/index.html129
-rw-r--r--files/pt-br/web/api/htmloptionelement/option/index.html101
2 files changed, 230 insertions, 0 deletions
diff --git a/files/pt-br/web/api/htmloptionelement/index.html b/files/pt-br/web/api/htmloptionelement/index.html
new file mode 100644
index 0000000000..3ec8c7c27a
--- /dev/null
+++ b/files/pt-br/web/api/htmloptionelement/index.html
@@ -0,0 +1,129 @@
+---
+title: HTMLOptionElement
+slug: Web/API/HTMLOptionElement
+tags:
+ - API
+ - HTML DOM
+ - Interface
+ - NeedsNewLayout
+ - NeedsTranslation
+ - Reference
+ - TopicStub
+translation_of: Web/API/HTMLOptionElement
+---
+<div>{{APIRef("HTML DOM")}}</div>
+
+<p>The <strong><code>HTMLOptionElement</code></strong> interface represents {{HTMLElement("option")}} elements and inherits all classes and methods of the {{domxref("HTMLElement")}} interface.</p>
+
+<p>{{InheritanceDiagram(600, 120)}}</p>
+
+<h2 id="Properties">Properties</h2>
+
+<p><em>Inherits properties from its parent, {{domxref("HTMLElement")}}.</em></p>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Name</th>
+ <th scope="col">Type</th>
+ <th scope="col">Description</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>defaultSelected</code></td>
+ <td>{{domxref("Boolean")}}</td>
+ <td>Contains the initial value of the {{htmlattrxref("selected", "option")}} HTML attribute, indicating whether the option is selected by default or not.</td>
+ </tr>
+ <tr>
+ <td><code>disabled</code></td>
+ <td>{{domxref("Boolean")}}</td>
+ <td>Reflects the value of the {{htmlattrxref("disabled", "option")}} HTML attribute, which indicates that the option is unavailable to be selected. An option can also be disabled if it is a child of an {{HTMLElement("optgroup")}} element that is disabled.</td>
+ </tr>
+ <tr>
+ <td><code>form</code>{{readonlyInline}}</td>
+ <td>{{domxref("HTMLFormElement")}}</td>
+ <td>If the option is a descendent of a {{HTMLElement("select")}} element, then this property has the same value as the <code>form</code> property of the corresponding {{DomXref("HTMLSelectElement")}} object; otherwise, it is <code>null</code>.</td>
+ </tr>
+ <tr>
+ <td><code>index</code>{{readonlyInline}}</td>
+ <td><code>long</code></td>
+ <td>The position of the option within the list of options it belongs to, in tree-order. If the option is not part of a list of options, like when it is part of the {{HTMLElement("datalist")}} element, the value is <code>0</code>.</td>
+ </tr>
+ <tr>
+ <td><code>label</code></td>
+ <td>{{domxref("DOMString")}}</td>
+ <td>Reflects the value of the {{htmlattrxref("label", "option")}} HTML attribute, which provides a label for the option. If this attribute isn't specifically set, reading it returns the element's text content.</td>
+ </tr>
+ <tr>
+ <td><code>selected</code></td>
+ <td>{{domxref("Boolean")}}</td>
+ <td>Indicates whether the option is currently selected.</td>
+ </tr>
+ <tr>
+ <td><code>text</code></td>
+ <td>{{domxref("DOMString")}}</td>
+ <td>Contains the text content of the element.</td>
+ </tr>
+ <tr>
+ <td><code>value</code></td>
+ <td>{{domxref("DOMString")}}</td>
+ <td>Reflects the value of the {{htmlattrxref("value", "option")}} HTML attribute, if it exists; otherwise reflects value of the {{domxref("Node.textContent")}} property.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Methods">Methods</h2>
+
+<p><em>Inherits methods from its parent, {{domxref("HTMLElement")}}.</em></p>
+
+<dl>
+ <dt>Option()</dt>
+ <dd>Is a constructor creating an <code>HTMLOptionElement</code> object. It has four values: the text to display, <code>text</code>, the value associated, <code>value</code>, the value of <code>defaultSelected</code>, and the value of <code>selected</code>. The last three values are optional.</dd>
+</dl>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', "#htmloptionelement", "HTMLOptionElement")}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5 W3C', "forms.html#the-option-element", "HTMLOptionElement")}}</td>
+ <td>{{Spec2('HTML5 W3C')}}</td>
+ <td>A constructor, <code>Option()</code>, has been added.<br>
+ The <code>form</code> property can be the <code>null</code> value.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('DOM2 HTML', 'html.html#ID-70901257', 'HTMLOptionElement')}}</td>
+ <td>{{Spec2('DOM2 HTML')}}</td>
+ <td>The <code>selected</code> property changed its meaning: it now indicates if the option is currently selected and no longer if it was initally selected.<br>
+ The <code>defaultSelected</code> property is no longer read-only.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('DOM1', 'level-one-html.html#ID-70901257', 'HTMLOptionElement')}}</td>
+ <td>{{Spec2('DOM1')}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("api.HTMLOptionElement")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>The HTML element implementing this interface: {{HTMLElement("option")}}.</li>
+</ul>
diff --git a/files/pt-br/web/api/htmloptionelement/option/index.html b/files/pt-br/web/api/htmloptionelement/option/index.html
new file mode 100644
index 0000000000..9027e9b799
--- /dev/null
+++ b/files/pt-br/web/api/htmloptionelement/option/index.html
@@ -0,0 +1,101 @@
+---
+title: Option()
+slug: Web/API/HTMLOptionElement/Option
+translation_of: Web/API/HTMLOptionElement/Option
+---
+<div>{{APIRef("HTML DOM")}}</div>
+
+<p>O construtor <strong><code>Option()</code></strong> cria novos {{domxref("HTMLOptionElement")}}.</p>
+
+<h2 id="Sintaxe">Sintaxe</h2>
+
+<pre class="syntaxbox">var <em>o</em><em>ptionElementReference</em> = new Option(<em>text</em>, <em>value</em>, <em>defaultSelected</em>, <em>selected</em>);</pre>
+
+<h3 id="Parâmetros">Parâmetros</h3>
+
+<dl>
+ <dt><code>text</code> {{optional_inline}}</dt>
+ <dd>Um {{domxref("DOMString")}} representa o conteúdo do elemento, o texto mostrado na tela. Se  o texto não é especificado, o texto padrão "" (texto vazio) é  utilizado.</dd>
+ <dt><code>value</code> {{optional_inline}}</dt>
+ <dd>Um {{domxref("DOMString")}} representa o valor do {{domxref("HTMLOptionElement")}}, i.e. o valor do elemento {{htmlelement("option")}}. Se não especificado, o texto é usado como valor, e.g. o elemento {{htmlelement("select")}} tem seu valor associado quando o formulário é submetido ao servidor.</dd>
+ <dt><code>defaultSelected</code> {{optional_inline}}</dt>
+ <dd>Um {{domxref("Boolean")}} é usado para adicionar o atributo <strong>selected</strong>, para que este {{htmlelement("option")}} seja mostrado como selecionado no elemento {{htmlelement("select")}} quando a página for carregada. Se não especificado, o estado padrão é não selecionado. Observe que o <strong>defaultSelected = true</strong> não define a opção como o valor selecionado do elemento {{htmlelement("select")}}.</dd>
+ <dt><code>selected</code> {{optional_inline}}</dt>
+ <dd>Um {{domxref("Boolean")}} é usado para colocar elemento {{htmlelement("option")}} no estado de selecionado; como padrão do elemento tem o estado de não selecionado. Se omitido, mesmo que o parâmetro <strong>defaultSelected </strong>for verdadeiro, o elemento {{htmlelement("option")}} não é selecionado. </dd>
+</dl>
+
+<h2 id="Examplos">Examplos</h2>
+
+<h3 id="Adicionando_novas_tags_options">Adicionando novas tags options</h3>
+
+<pre class="brush: js"> /* <code class="language-js">assumindo que temos este HTML</code>
+&lt;select id='s'&gt;
+
+&lt;/select&gt;
+*/
+
+var s = document.getElementById('s');
+var options = [Quatro, Cinco, Seis];
+
+options.forEach(function(elemento, chave) {
+ s.appendChild(new Option(elemento, chave));
+});
+
+ /* <code class="language-js">Resultado
+</code>&lt;select id='s'&gt;
+ &lt;option value="0"&gt;Quatro&lt;/option&gt;
+ &lt;option value="1"&gt;Cinco&lt;/option&gt;
+  &lt;option value="2"&gt;Seis&lt;/option&gt;
+&lt;/select&gt; */
+</pre>
+
+<h3 id="Adicionando_options_com_diferentes_parâmetros">Adicionando options com diferentes parâmetros</h3>
+
+<pre class="brush: js"><code class="language-js">/* assumindo que temos este HTML
+&lt;select id="s"&gt;
+ &lt;option&gt;Primeiro&lt;/option&gt;
+ &lt;option&gt;Segundo&lt;/option&gt;
+ &lt;option&gt;Terceiro&lt;/option&gt;
+&lt;/select&gt;
+*/
+
+var s = document.getElementById('s');
+</code>var options = [ 'zero', 'um', 'dois' ];<code class="language-js">
+
+options.forEach(function(elemento, chave) {</code>
+ if (elemento == 'zero') {
+ s[s.options.length] = new Option(elemento, s.options.length, false, false);
+ }
+ if (elemento == 'um') {
+ s[s.options.length] = new Option(elemento, s.options.length, true, false); // Adicionando atributo "selected"
+ }
+ if (elemento == 'dois') {
+ s[s.options.length] = new Option(elemento, s.options.length, false, true); // Apenas irá selecionar a opção na visualização
+ }
+<code class="language-js">});
+
+/* Resultado
+&lt;select id="s"&gt;
+ &lt;option value="0"&gt;zero&lt;/option&gt;
+ &lt;option value="1" selected=""&gt;um&lt;/option&gt;
+ &lt;option value="2"&gt;dois&lt;/option&gt; // O usuário verá esta opção selecionada
+&lt;/select&gt;
+</code>*/</pre>
+
+<h2 id="Especificação">Especificação</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificação</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comentário</th>
+ </tr>
+ <tr>
+ <td><a class="external external-icon" href="http://www.w3.org/TR/2012/WD-html5-20121025/the-option-element.html#dom-option" hreflang="en" lang="en">HTML5<br>
+ <small lang="en-US">The definition of 'Option' in that specification.</small></a></td>
+ <td>Recomendado</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>