开发者

What is the output element? [closed]

开发者 https://www.devze.com 2023-03-14 08:47 出处:网络
开发者_Python百科 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current for
开发者_Python百科 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Man, I don't get the output element at all.

Q: What is it?


The output element is just adding semantic meaning to the markup. It's harder to understand since we are used to the input element which browsers always render using some UI whereas the output element does not have any associated UI (as in a div element).

The onforminput event (as shown in one of the answers) has been deprecated and oninput event should be used instead:

<form oninput="result.value=a.valueAsNumber + b.valueAsNumber">
  <input type="range" name="a"> + 
  <input type="number" name="b"> =
  <output name="result"></output>
</form>

However, this is only a specific use case of the output tag and it's not necessary that javascript handles the result automatically. Any kind of output even if it's handled manually will suffice.


You would set an onforminput event listener to it and then make calculations based on other input tags within the same form and set its value based on those calculations.

<input name="add_me" type="number"> +
<input name="me_too" type="number"> =
<output name="result" onforminput="value = add_me.valueAsNumber + me_too.valueAsNumber"></output>


Seems to me it's exactly what it says on the tin. It indicates the result of some calculation done somewhere else on your page.

0

精彩评论

暂无评论...
验证码 换一张
取 消